Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
EgorkaKulikov opened this issue May 24, 2022 · 0 comments · Fixed by #15
Closed

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

EgorkaKulikov opened this issue May 24, 2022 · 0 comments · Fixed by #15
Assignees
Labels
comp-symbolic-engine Issue is related to the symbolic execution engine ctg-bug Issue is a bug

Comments

@EgorkaKulikov
Copy link
Collaborator

EgorkaKulikov commented May 24, 2022

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.

@EgorkaKulikov EgorkaKulikov added the ctg-bug Issue is a bug label May 24, 2022
@alexeyfridman alexeyfridman moved this to Todo in UTBot Java May 26, 2022
@alexeyfridman alexeyfridman moved this from Todo to Done in UTBot Java May 26, 2022
@EgorkaKulikov EgorkaKulikov added the comp-symbolic-engine Issue is related to the symbolic execution engine label May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-symbolic-engine Issue is related to the symbolic execution engine ctg-bug Issue is a bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants