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

improve setting assertion status for javac

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P3 P3
    • 7
    • 7
    • tools
    • generic
    • generic

      javac contains assert statements that it normally expects to be "active" -- that is, it expects assertions to be enabled. This is typically handled by the bin/javac launcher which is built with

      ifeq ($(PROGRAM),javac)
       WILDCARDS=true
       MAIN_JAVA_ARGS += -J-Xss4m -J-ea:com.sun.tools...
       NEVER_ACT_AS_SERVER_CLASS_MACHINE=true
      endif

      However, it is increasingly common to invoke javac via API. To that end, com.sun.tools.javac.Main includes the following:

          static {
              ClassLoader loader = Main.class.getClassLoader();
              if (loader != null)
                  loader.setPackageAssertionStatus("com.sun.tools.javac", true);
          }

      That'll work for Ant, jtreg, etc, most of the time, but it will not work if Main.class.getClassLoader() returns null, typically meaning the bootstrap classloader. This is common if javac is invoked using -J-Xbootclasspath:javac.jar, as in common in langtools development.

      To that end, this code would be better written as

          static {
              ClassLoader loader = Main.class.getClassLoader();
              if (loader == null)
      loader = ClassLoader.getSystemClassLoader();
              loader.setPackageAssertionStatus("com.sun.tools.javac", true);
          }

            jjg Jonathan Gibbons
            jjg Jonathan Gibbons
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: