Re: [Jastadd] [bug report] no need to be a static field to have the ConstantValue attribute

From: Jesper Öqvist <jesper.oqvist_at_cs.lth.se>
Date: Fri, 04 May 2012 15:28:51 +0200

The bug has been fixed in SVN revision 9258 with your proposed fix!

Thank you for the bug description and concise test case!

/Jesper

On 04/30/2012 07:45 AM, Na, Hyunik wrote:
>
> 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.
>
>
> _______________________________________________
> JastAdd mailing list
> JastAdd_at_cs.lth.se
> https://mail1.cs.lth.se/cgi-bin/mailman/listinfo/jastadd
Received on Fri May 04 2012 - 15:28:10 CEST

This archive was generated by hypermail 2.3.0 : Wed Apr 16 2014 - 17:19:06 CEST