Bug 118326 - [itd] inter-type field declarations with initializers should be type checke
Summary: [itd] inter-type field declarations with initializers should be type checke
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.0M5   Edit
Hardware: PC Windows XP
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-28 18:07 EST by A.T. CLA
Modified: 2013-06-24 11:03 EDT (History)
1 user (show)

See Also:


Attachments
The example files: Foo.java, Bar.java (339 bytes, application/zip)
2005-11-28 18:09 EST, A.T. CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description A.T. CLA 2005-11-28 18:07:46 EST
With the AspectJ 1.5.0M5 compiler, an inter-type field declaration of type int with an initializer is not type-checked to prevent an attempt to assign null into the field by default.  The result is a VerifyError at runtime.

Is this the intended behavior?  I couldn't find any evidence in the AspectJ documentation that initializers on inter-type field declarations should not be type checked, but I can't admit to being particularly experienced with AspectJ.

Here is code that reproduces the problem:

------------------
// Foo.java
public class Foo {
    public static void main(String[] args) {
        Foo f = new Foo();
    }
}
------------------
// Bar.java
public aspect Bar {
    public int Foo.x = null;
}
------------------
I compiled the code with the following command:

    ajc -1.5 -source 1.5 Foo.java Bar.java
Comment 1 A.T. CLA 2005-11-28 18:09:13 EST
Created attachment 30735 [details]
The example files: Foo.java, Bar.java
Comment 2 Andrew Clement CLA 2005-11-29 16:04:57 EST
almost got a fix for this...
Comment 3 Andrew Clement CLA 2005-12-02 06:23:29 EST
turns out my 'almost fix' breaks some other testcases.  The problem is that there is no validity checking for the 'initialization' object for an intertype field declaration.  The solution is to copy the validation logic from FieldDeclaration.resolve(MethodScope) - about line 207 - into the IntertypeFieldDeclaration resolve() method.  This then causes my test programs for this bug to pass (the test programs *are* checked into CVS, but commented out in Ajc150Tests).  However, there are side effects in that initialization checking code (seems to be this call: initializationType = this.initialization.resolveType(initializationScope)) which cause other tests to break...  as this is a long standing problem and we *need* to get 1.5.0 finished, I'm deferring for a proper look in 1.5.1...

Comment 4 Andrew Clement CLA 2013-06-24 11:03:50 EDT
unsetting the target field which is currently set for something already released