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

a bug in soot (coffi)



Hi,

When reading a paper, I noticed a bug in Soot (or likely in Coffi). I describe it here and if someone is using soot actively, he/she may fix it quickly. (I can do it too, but less efficient than others right now :-P )

The problem is that, Soot losts the ConstantValue attribute of a static field when transferring a class file to its internal format, this is due to some static fields not initialized in <clinit> explicitly. Example:

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

testconst.java
public class testconst {
 public static void main(String[] args) {
   System.out.println(z);
 }
}

We can compile both .java files using javac 1.4.2. Then we change testconstA.java to

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

and recompile modified testconstA only (don't recompile testconst.java, you can see the difference by sootify both). The resulted class files are legal. The only difference of testconstA.class after modification is that, there is no <clinit> in the modified version, because 'z' is *final* now, which lets javac compiled '7' to be a ConstantValue attribute of the field *z*.

If we run > java testcont < now, it gives correct output. But if we sootify *modified* testconstA.class, the ConstantValue attribute of *z* was lost. So far, the problem should be clear.

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>, see JVM spec version 2, Section 4.7.2.

I already saw ConstantValue attributes were parsed in Coffi, it is only a matter to convert it to an assignment in <clinit>.

Cheers,
Feng