Community
Participate
Working Groups
Using latest, the assertion status is checked against the current class instead of the most enclosing type. From http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.10: An assert statement is enabled if and only if the top-level class (§8) that lexically contains it enables assertions. Whether or not a top-level class enables assertions is determined by its defining class loader before the class is initialized (§12.4.2), and cannot be changed thereafter. Try this test case: public class X { static class Y { public static void test() { assert false; System.out.println("SUCCESS"); } } public static void main(String[] args) { ClassLoader classLoader = new X().getClass().getClassLoader(); // enable assertion for X.Y classLoader.setClassAssertionStatus("X$Y", true); X.Y.test(); } } Then run it without enabling assertion at runtime: java X You will get an AssertionError. If the assertionStatus of the nested type would be retrieved from the most enclosing type, the assert statement should be ignored and the result should be: "SUCCESS".
Created attachment 50199 [details] Proposed fix for 3.2 maintenance branch
Created attachment 50208 [details] Regression tests for 3.2 maintenance branch
Created attachment 50224 [details] Proposed fix for 3.2 maintenance branch Better patch for 1.4. It doesn't change anything for 1.6 or 1.5 mode.
The first patch is the one to keep. This case needs more work in 1.4 mode, but it is fine in 1.5 and 1.6 mode. In 1.5 or 1.6 the ldc bytecode can be used to retrieve the class. In 1.4, we need to do some macro expansion.
Created attachment 50225 [details] Proposed fix The first patch is allright in the 1.4 case. It puts the synthetic field on the enclosing type that uses the assert statement. The check for the desiredAssertionStatus is done on the most enclosing type anyway. However we can move the search for the sourceType inside the then block of the if since it is used only if the condition is true. It doesn't change the behavior of the previous patch.
Released for 3.3M2. Regression test added org.eclipse.jdt.core.tests.compiler.regression.AssertionTest#test013.
+1 for 3.2 maintenance (3.2.1)
Released for 3.2.1. Same regression test added.
Verified for 3.2.1 using build M20060915-1045
Verified for 3.3 M2 using build I20060918-0010.