The ConstantValueToInitializerTransformer ensures for instance fields initialized with a default constant value, that constructor implementation(s) have the constant assignment to such instance fields immediately after the call to super constructor. For final instance fields with constant initializers, however, the constant assignment statement is already present in the generated Jimple body of the constructor(s), and furthermore its ordinal position within the body should not matter since they cannot be overwritten. Since the current implementation does not check for this case, a duplicate copy of such constant assignment statements are introduced.
This behavior can affect downstream analyses- e.g., we observe that Tags computed from a liveness analysis are lost when such constant assignment statements are incorrectly duplicated.
Solution
We check for the presence of an existing assignment statement that initializes the given instance field with the given constant value (isInstanceFieldAssignedConstantInBody()), and avoid duplication if present.
Note: we observe that these constants are already initialized as expected in the bytecode generated by modern Java compilers and do not know under which circumstances this transformation would be necessary. So, we simply check for the above condition to avoid duplication.
Problem
The
ConstantValueToInitializerTransformer
ensures for instance fields initialized with a default constant value, that constructor implementation(s) have the constant assignment to such instance fields immediately after the call tosuper
constructor. Forfinal
instance fields with constant initializers, however, the constant assignment statement is already present in the generated Jimple body of the constructor(s), and furthermore its ordinal position within the body should not matter since they cannot be overwritten. Since the current implementation does not check for this case, a duplicate copy of such constant assignment statements are introduced. This behavior can affect downstream analyses- e.g., we observe that Tags computed from a liveness analysis are lost when such constant assignment statements are incorrectly duplicated.Solution
We check for the presence of an existing assignment statement that initializes the given instance field with the given constant value (
isInstanceFieldAssignedConstantInBody()
), and avoid duplication if present.Testing
mvn clean verify