[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a bug in soot (coffi)



From JVM Spec:

The constant field represented by the |field_info| structure is assigned the value referenced by its |ConstantValue| attribute as part of the initialization of the class or interface declaring the constant field (§2.17.4) <http://java.sun.com/docs/books/vmspec/2nd-edition/html/Concepts.doc.html#19075>. This occurs immediately prior to the invocation of the class or interface initialization method (§3.9) <http://java.sun.com/docs/books/vmspec/2nd-edition/html/Overview.doc.html#12174> of that class or interface.

Probably it is not as worse as you may think ;-) .

Cheers,
Feng


Etienne Gagnon wrote:


Hi Feng,

Feng Qian wrote:

...
testconstA.java modified
public class testconstA {
public static final z = 7;
}
The solution is to assign the value of ConstantValue attribute to a static field in <clinit> explicitly (create one if no <clinit> exists) before any other real code in original <clinit>...


So, you are saying that you want to change such a class into:

testconstA.java modified again
public class testconstA {
 public static final z;
 static {
  z = 7;
 }
}

I would really prefer that the ConstantValue attribute be preserved
instead of adding an assignment statement.  Execution of static blocks
happen at a later time than initialization of fields with ConstantValue
attributes, according to the JVM spec.  [In other words, constant fields
are initialized with their value before <clinit>() is called].

Etienne