[Jastadd] [bug report] no need to be a static field to have the ConstantValue attribute
 
Hello JastAddJ developers, 
 
In Attributes.jrag in Java1.4Backend, FieldDeclaration.attributes() is
defined as follows: 
 
-=-=-=
  eq FieldDeclaration.attributes() {
    ArrayList l = new ArrayList();
    if(isStatic() && isFinal() && isConstant() && (type().isPrimitive() ||
type().isString())) 
      l.add(new ConstantValueAttribute(hostType().constantPool(), this));
    return l;
}
-=-=-=
 
It seems that the "iStatic() &&" should be dropped from the if-condition 
because a ConstantValue attribute can be generated for a non-static field. 
That is, the condition is too strict.
 
Because of this, JastAddJ rejects a correct program as described below.
 
1. Put the following A.java and B.java in a directory: 
 
-=-=-= A.java
class A extends B {
  void test() {
    short s = b;
  }
}
-=-=-=
 
-=-=-= B.java
class B {
  final int b = 7;
}
-=-=-=
 
2. Compile A.java with JastAddJ's JavaCompiler. Then it will be compiled
fine.
 
3. Compile B.java to generate B.class. 
 
4. Compile A.java again. (Now, unlike in step 2, class B is loaded from
B.class rather than from B.java because of step 3)
Unlike in step 2, an error message is emitted.
 
-=-=-=
Errors:
A.java:3:
  Semantic Error: can not assign s of type short a value of type int
-=-=-=
 
The b field in the JastAddJ generated B.class does not have ConstantValue
attribute (because it is not static), 
and hence it is not taken as a constant when loaded from the class file
(but, it is when loaded from B.java).
So, narrowing from int to short is not allowed in the assignment at line 3
of A.java when loaded from the class file. 
 
This problem was observed when compiling
sun/reflect/MethodAccessorGenerator.java in the OpenJDK1.6
 
Please check this.
 
- Hyunik.
 
Received on Mon Apr 30 2012 - 07:45:15 CEST
This archive was generated by hypermail 2.3.0
: Wed Apr 16 2014 - 17:19:06 CEST