Bug 62606

Summary: ITCs don't run field initialisers
Product: [Tools] AspectJ Reporter: Oege de Moor <oege>
Component: CompilerAssignee: Adrian Colyer <adrian.colyer>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P2    
Version: 1.2   
Target Milestone: 1.5.0RC1   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Oege de Moor CLA 2004-05-18 04:35:04 EDT
/* ITC's don't run field initialisers.

   Intertype constructors cannot possibly run the field initialisers of 
   the target when you're weaving into byte code. ajc appears to take this 
   as a license not to run the field initialisers, even when weaving into
   source.
Comment 1 Oege de Moor CLA 2004-05-18 04:39:41 EDT
/* ITC's don't run field initialisers.

   Intertype constructors cannot possibly run the field initialisers of 
   the target when you're weaving into byte code. ajc appears to take this 
   as a license not to run the field initialisers, even when weaving into
   source. This is illustrated by the program below.

   Requests: 
   * print warning when ITC applies to bytecode and does not call an
     existing constructor; 
   * do run field initialisers when weaving into
     source and there is no call to an existing constructor.
   

*/

aspect Aspect {
    public A.new(int a) {} // no init of z
}

class A {
    int z = 3;
    public A() { } // init of z=3
}

public class ITA3 {
    public static void main(String[] args) {
        System.out.println(new A(4).z); // print 0
        System.out.println(new A().z);  // print 3
    }
}

Comment 2 Adrian Colyer CLA 2005-03-22 09:04:33 EST
this needs looking into in the AJ5 timeframe...
Comment 3 Adrian Colyer CLA 2005-10-28 05:57:09 EDT
we need to at least add the suggested warning before 1.5.0 RC1 - the current behaviour will be very 
surprising to users (if seldom encountered...)
Comment 4 Adrian Colyer CLA 2005-11-03 12:13:21 EST
Warning implemented. If an ITDC does not contain an explicit cons call a new 
Xlint:noExplicitConstructorCall warning is issued. This can be suppressed using the @SuppressAjWarnings 
or @SuppressAjWarnings({"noExplicitConstructorCall"}) forms if desired.