Bug 72245 - inconsistent treatment of set field join points at initialisers of final fields
Summary: inconsistent treatment of set field join points at initialisers of final fields
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-19 06:48 EDT by Ganesh Sittampalam CLA
Modified: 2004-08-20 05:40 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 Ganesh Sittampalam CLA 2004-08-19 06:48:01 EDT
The program below only reports a join point at the set of y, and not of x, which
seems clearly wrong. I get the same behaviour when I make foo() return false
instead of true.

I'm using 'DEVELOPMENT built on Monday Aug 16, 2004 at 13:50:47 GMT'

public class FieldInit {
    public static final int x=foo() ? bar(): 2;
    public static final int y=!foo() ? 2: bar();

    static boolean foo() {
	return true;
    }
    static int bar() { return 3; }
    public static void main(String[] args) {
    }

}

aspect FIAspect {
    before() : set(int FieldInit.*) { System.out.println(thisJoinPointStaticPart); }
}
Comment 1 Erik Hilsdale CLA 2004-08-19 12:26:49 EDT
Yep, this is a bug.  There's a bit of weirdness in AspectJ relating to constant
fields, but clearly by JLS 15.28, neither x nor y is a constant field due to the 
static method call.  I'll take a look at this; it's possible that someone 
(the Eclipse front end) is overoptimizing and marking x constant.
Comment 2 Ganesh Sittampalam CLA 2004-08-19 12:37:03 EDT
Is the precise specification that the initialization of a final variable with a
constant expression should not be treated as a join point? If so, how is this
detected in bytecode which contains such an initialization?
Comment 3 Erik Hilsdale CLA 2004-08-19 12:43:08 EDT
We assume that fields with ConstantValueAttributes are constant.  Existing java
compilers are pretty good about NOT generating a PUTSTATIC for such fields. 
Check for yourself by decompiling

  class Test {
      public static int i = 3;
  }

Comment 4 Ganesh Sittampalam CLA 2004-08-19 12:57:24 EDT
That's true for static fields, but it doesn't seem to be for non-static fields,
and the new/FieldInitializerJoinPoints.java file in the ajc tests seems to
suggest that they should also not be treated as join points if they have a
constant initializer.
Comment 5 Erik Hilsdale CLA 2004-08-19 13:44:32 EDT
My initial take on this is that new/FieldInitializerJoinPoints.java 
may just be wrong.  The problem comes from this really cool bit
o' code:

public class Test {
    public final int x= 3;

    public static void main(String[] args) {
	Test t = new Test();
	t.foo();
    }
    void foo() {
	System.err.println(x);  // a constant reference
	System.err.println(this.x);  // NOT a constant reference
    }
}

the field x, in this case, is a weird thing in Java:  a field that,
when referred to by plain name, must be inlined, but must also have a
runtime value for when it is referred to by qualified name.

For some reason we decided that this was a "constant field" and should
have no set join point.  I'm starting to believe that this should
have a set join point.  The semantics appendix currently (under the
"join points" section) only defines constant fields as static final
fields whose initializer is a constant string object or primitive value,
and I _think_ we should probably migrate the compiler to this behavior
as well.

(Not that we're sure any of this has to do with the actual bug we're
dealing with... Hmm.  Maybe we should create a new bug report crying foul at
new/FieldInitializerJoinPoints.java and move some of the discussion
over there)
Comment 6 Ganesh Sittampalam CLA 2004-08-20 05:40:18 EDT
Discussion about instance field join points moved to bug 72335.