Skip to content

Do not set final fields with direct accessors in UtAssembleModel #14

@EgorkaKulikov

Description

@EgorkaKulikov

Suppose we have a class with a public final field whose content can be modified (e.g., an array):

public class PublicFinalFieldExample { public final int[] data = {1, 2};   public boolean foo(int x) { return x == data[0]; } } 

Expected behavior:
UtAssembleModel is not created, final field is set via reflection.

Actual behavior:
The generated tests for foo contain the direct assignment to the data field instead of assignment to the array elements or changing the field value using reflection:

@Test -- @DisplayName("foo: return data[0] == x : False -> return data[0] == x") public void testFoo_0OfDataNotEqualsX() throws Throwable { PublicFinalArrayExample publicFinalArrayExample = new PublicFinalArrayExample(); int[] intArray = new int[1]; intArray[0] = 1; publicFinalArrayExample.data = intArray; // Error: this line does not compile   boolean actual = publicFinalArrayExample.foo(-224);   assertFalse(actual); } 

Testing instructions:
AssembleModelGeneratorTests should be enlarged with one more test for objects with final fields.
Other tests should still pass.

Metadata

Metadata

Assignees

Labels

comp-symbolic-engineIssue is related to the symbolic execution enginectg-bugIssue is a bug

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions