Skip to content

Fix direct assigning of fields with private type #731 #735

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

Conversation

volivan239
Copy link
Collaborator

@volivan239 volivan239 commented Aug 17, 2022

Description

If we have a public field with type that is not accessible in testclass, then we should use reflection but not direct assignments to set it (because rhs will likely be declared as Object).

Fixes #731

Type of Change

  • Minor bug fix (non-breaking small changes)

How Has This Been Tested?

Automated Testing

Added org.utbot.examples.codegen.ClassWithStaticAndInnerClassesTest#testGetValueFromPublicFieldWithPrivateType

Manual Scenario

Launch plugin on example from #731 -- works as expected.

Checklist (remove irrelevant options):

This is the author self-check list

  • 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

@volivan239 volivan239 marked this pull request as ready for review August 17, 2022 14:55
@volivan239 volivan239 requested a review from dtim August 17, 2022 14:58
Copy link
Collaborator

@dtim dtim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

check(
ClassWithStaticAndInnerClasses::getValueFromPublicFieldWithPrivateType,
eq(2),
coverage = DoNotCalculate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JFYI: it would be better to use coverage = DoNotCalculate only to avoid false positive test failure when coverage computation returns wrong results (it seems that it is the case here) although the set of executions is correct. It would also be useful to add matchers to be sure that executions of interest have been really found.

I think this test can be left as is, as it only provides data to the integration test (the only way to check the codegen) and follows the style of existing examples. Nevertheless, adding matchers could help to detect engine bugs as well.

@volivan239 volivan239 changed the title Fixed direct assigning of fields with private type #731 Fix direct assigning of fields with private type #731 Aug 18, 2022
@volivan239 volivan239 merged commit 0ee76e2 into main Aug 18, 2022
@volivan239 volivan239 deleted the volivan239/fix_direct_assigning_object_to_typed_fields branch August 18, 2022 08:16
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.

Class cast is missing for the instance of private nested class
2 participants