ArrayIndexOutOfBoundsException in Parser due to static init block #3524
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.
issue #3506
What it does
The static initializer block initializations were wrongly interpreted as field declarations of the record which resulted in removing intPtr entries - additional entries than required. This resulted in wrong integer values for dimensions - as an example the source position integer was written as dimensions though the dimension was zero - and subsequent looping through the dimensions resulted in AIOOBE. The root cause was identified as the erroneous interpretation of the initializations with var declarations as Field Declarations of Records. This is corrected in the PR.
The check is being done by checking whether the nesting method level is the same as that of the record - based on the fact that the static initializer block will increment the nesting level. If a declaration is inside this static initializer block, the values would be differnt at the point of testing. Thus the fix.
How to test
A new test has been added which captures this by using a local record with a static field. Though not allowed and this has resulted in a negative test case, the fix is captured/covered by this test case - removal of the fix would result in the AIOOBE being thrown with this test case.
Author checklist