Skip to content

Change type of 'actual' variable #631

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

Merged
merged 1 commit into from
Aug 1, 2022
Merged

Conversation

ArsenHD
Copy link
Collaborator

@ArsenHD ArsenHD commented Aug 1, 2022

Description

Before, the type of this variable was the same as the return type of executable under test. However, this could lead to undesired reflection usage: if a method returns A, but the real type of actual variable is B (subclass of A), then we will not be able to access fields that are declared in B without reflection, because the variable is declared with type A. For example, this can happen when we make equality assertions between fields of expected value and an actual result and some of these fields are from B, but are not accessible, because type A knows nothing about these new fields.

Type of Change

  • Minor bug fix (non-breaking small changes)

How Has This Been Tested?

This change simply fixes unnecessary reflection usage. So, all tests worked before and should work after this change. The difference is that we will be able to avoid using reflection to access fields of variable actual.

Automated Testing

The difference can be seen on org.utbot.examples.objects.ObjectWithPrimitivesExample#max. If you generate tests for this method before this change, then the field anotherX of the variable actual will be accessed via reflection, whereas after the change a regular field access is used.

Checklist:

  • The change followed the style guidelines of the UTBot project
  • Self-review of the code is passed
  • The change contains enough commentaries, particularly in hard-to-understand areas
  • New documentation is provided or existed one is altered
  • No new warnings
  • New tests have been added
  • All tests pass locally with my changes

Before the type of this variable was the same as the return type of executable under test. However, this could lead to undesired reflection usage: if a method returns 'A', but the real type of 'actual' variable is 'B' (subclass of A), then we will not be able to access fields that are declared in 'B' without reflection, because the variable is declared with type 'A'. For example, this can happen when we make assertions on field modifications and some of these fields are from 'B', but are not accessible, because type 'A' knows nothing about these new fields.
@ArsenHD ArsenHD requested review from EgorkaKulikov and Damtev August 1, 2022 14:34
@EgorkaKulikov EgorkaKulikov merged commit 2c69326 into main Aug 1, 2022
@EgorkaKulikov EgorkaKulikov deleted the ArsenHD/actual-var-type-fix branch August 1, 2022 16:07
tamarinvs19 pushed a commit that referenced this pull request Aug 4, 2022
Before the type of this variable was the same as the return type of executable under test. However, this could lead to undesired reflection usage: if a method returns 'A', but the real type of 'actual' variable is 'B' (subclass of A), then we will not be able to access fields that are declared in 'B' without reflection, because the variable is declared with type 'A'. For example, this can happen when we make assertions on field modifications and some of these fields are from 'B', but are not accessible, because type 'A' knows nothing about these new fields.
denis-fokin pushed a commit that referenced this pull request Aug 18, 2022
Before the type of this variable was the same as the return type of executable under test. However, this could lead to undesired reflection usage: if a method returns 'A', but the real type of 'actual' variable is 'B' (subclass of A), then we will not be able to access fields that are declared in 'B' without reflection, because the variable is declared with type 'A'. For example, this can happen when we make assertions on field modifications and some of these fields are from 'B', but are not accessible, because type 'A' knows nothing about these new fields.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants