Bug 385923 - Assertions in aspects cannot be disabled with commandline arguments
Summary: Assertions in aspects cannot be disabled with commandline arguments
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-25 06:19 EDT by C de Gouw CLA
Modified: 2012-07-25 10:21 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description C de Gouw CLA 2012-07-25 06:19:50 EDT
Build Identifier: AspectJ Compiler 1.7.0 (1.7.0 - Built: Tuesday Jul 3, 2012 at 22:30:30 GMT) - Eclipse Compiler 0.B79_R37x, 3.7

Assertions in aspects are evaluated even when explicitly disabling them with the 'java -da -dsa ...' command-line argument. The generated bytecode seems wrong: the static $assertionsDisabled variable (which is added to any class/aspect containg an assert statement) is never initialized in aspects.

The bytecode generated for normal classes starts with:

static {};
  Code:
   0:	ldc	#1; //class Test2
   2:	invokevirtual	#10; //Method java/lang/Class.desiredAssertionStatus:()Z
   5:	ifne	12
   8:	iconst_1
   9:	goto	13
   12:	iconst_0
   13:	putstatic	#16; //Field $assertionsDisabled:Z

Which sets $assertionsDisabled to 1 or 0 depending on the value desiredAssertionStatus returned for that class (which in turn depends on the -da command line argument). This bytecode is missing in the static {}; section for aspects.

Reproducible: Always

Steps to Reproduce:
1. Compile the following code with aspectj, source level 1.5 or higher:
public class Test1 {
    public static void main(String[] args) {
      m();
    }
    public static void m() {
      ;
    }
}

aspect Test1Aspect {
    before():  call(public static void Test1.m()) {
	assert false;
    }
}

2. Executing 'java -da -dsa Test1' results in an AssertionError, even though the -da -dsa command-line parameters should prevent any assertions from being checked.