Check for ArrayStoreException on array update #971
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a check to
TraversalContext.traverseAssignLeftPart
to detect ifArrayStoreException
should be thrown for the given array element assignment statement.The exception is generated if the type of the value on the right-hand side of the assignment is not a subtype of the array elements type and is not null.
This change affects all code that explicitly assigns array elements, as well as all calls to
Objects.arraycopy
and similarArrays
static methods.Fixes #923
Type of Change
Breaking change (fix or feature that would cause existing functionality to not work as expected)
New executions may be generated for the code that involves array modification.
How Has This Been Tested?
Automated Testing
All existing unit tests should pass.
A new test suite
org.utbot.examples.arrays.ArrayStoreExceptionExamplesTest
has been added, it should pass both with and without concrete execution.Manual Scenario
Generate a test suite (with fuzzer turned off) for a method that assigns values to array elements of a incompatible reference type, e.g.:
A single test should be generated, that corresponds to
ArrayStoreException
:Checklist
This is the author self-check list