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);
}
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);
}
- relates to
-
JDK-6396503 javac should not require assertions enabled
- Closed