Bug 62606 - ITCs don't run field initialisers
Summary: ITCs don't run field initialisers
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.2   Edit
Hardware: PC Linux
: P2 enhancement (vote)
Target Milestone: 1.5.0RC1   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-18 04:35 EDT by Oege de Moor CLA
Modified: 2005-11-03 12:13 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.