Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8173253

Some assertions can't be disabled using "-disableassertions"

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_121"
      Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      assertion can be executed before "clinit" (AFAIK JLS, JVMS, etc do not have restrictions on this), while current implementation of the mechanism to disable assertions requires execution of "clinit" to initialize synthetic field "$assertionsDisabled".

      Background Info: I'm a developer of the JaCoCo code coverage library. While preparing test cases for cyclic class initialization I encountered this issue and isolated a simple reproducer.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the source code that is provided below, then execute with "-disableassertions".

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      "-disableassertions" disables assertions.
      ACTUAL -
      Assertion is not disabled.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class BadCycleClass {

        public static class Base {
          static final Child b = new Child();

          static {
            b.someMethod();
          }
        }

        public static class Child extends Base {
          static {
            System.out.println("childclinit");
          }

          public Child() {
            System.out.println("childinit");
          }

          void someMethod() {
            System.out.println("childsomeMethod");
            // AssertionError even with "-disableassertions"
            assert 1 == 2;
          }

        }

        public static void main(String[] args) {
          new Child();
        }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Don't test wired corner cases ;-)

            godin Evgeny Mandrikov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: