Skip to content

test: Fixed nondeterministic failure in createTests()#6493

Open
yonghanlin wants to merge 2 commits intoINRIA:masterfrom
yonghanlin:fix/invalid-import-and-pattern-roles
Open

test: Fixed nondeterministic failure in createTests()#6493
yonghanlin wants to merge 2 commits intoINRIA:masterfrom
yonghanlin:fix/invalid-import-and-pattern-roles

Conversation

@yonghanlin
Copy link
Contributor

What does this PR do?

This PR fixes a nondeterministic test failure in ReplaceParametrizedTest.createTests() within . module when running with NonDex.

Problem

The nondeterminism occurs because the test generates candidate CtElement instances from collections whose iteration order is not guaranteed. Depending on the iteration order, the test may produce element types that are incompatible with the role being tested:

  • For IMPORT_REFERENCE, a CtLocalVariableReference could be selected, which is not an importable reference.
  • For PATTERN, a CtUnnamedPattern could be selected, which is only valid inside record patterns.

Reproduce Test

To reproduce the failure, run NonDex on . module using the following commands:

mvn -pl . edu.illinois:nondex-maven-plugin:2.1.7:nondex -Dtest=spoon.test.replace.ReplaceParametrizedTest#createTests

The Fix

  • For IMPORT_REFERENCE, itemType is set to CtTypeReference.class, ensuring the created element is always an importable reference.
  • For PATTERN, if the generated argument is an instance of CtUnnamedPattern, it is replaced by a valid CtTypePattern with its type set to Object.

@yonghanlin yonghanlin changed the title fix: Prevent invalid argument selection for import and pattern roles in ReplaceParametrizedTest fix: Prevent nondeterministic behavior in createTests() Oct 23, 2025
@yonghanlin yonghanlin changed the title fix: Prevent nondeterministic behavior in createTests() test: Fixed nondeterministic failure in createTests() Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant