Skip to content

Conversation

@lycoris106
Copy link

Summary

Fixes nondeterministic failure caused by reflection order of Class.getDeclaredFields(). The failure was found with NonDex, which explores non-determinism in tests.

Root Cause

ReflectionUtils.doWithFields() iterates declared fields in an undefined order.
As a result, the exception message may reference the field [street] or [city] first, leading to intermittent assertion mismatches in the test.

Fix

Relaxed the assertion to accept either field name using hasMessageMatching(".(street|city)."), since modifying the code under test is neither practical nor necessary in this case:

.hasMessageMatching(".*Missing @Element annotation in mapped tuple type for property \\[(street|city)\\].*");

Notes

Test-only change, no impact on production code.

Reproduction of Failure

  • JVM version

openjdk version "17.0.16" 2025-07-15
OpenJDK Runtime Environment (build 17.0.16+8-Ubuntu-0ubuntu124.04.1)
OpenJDK 64-Bit Server VM (build 17.0.16+8-Ubuntu-0ubuntu124.04.1, mixed mode, sharing

  • Maven

Apache Maven 3.9.11

  • Original commit: 3239d1b

  • Add one line to pom.xml to skip verification when run with NonDex

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-surefire-plugin</artifactId>
	<configuration>
+	         <argLine>-Xverify:none</argLine>
  • Commands to reproduce
mvn -pl spring-data-cassandra edu.illinois:nondex-maven-plugin:2.1.7:nondex \
    -Dtest=org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentTupleEntityUnitTests#shouldReportMissingAnnotations \
    -Djacoco.skip -Drat.skip -Dpmd.skip -Denforcer.skip 

…raPersistentTupleEntityUnitTests.

ReflectionUtils.doWithFields() iterates fields in undefined order,
causing test failures expecting [street] vs [city]. Relaxed assertion
to accept both using hasMessageMatching(".*(street|city).*").

Signed-off-by: Chih-Fu Lai <lycoris1062@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 5, 2025
@mp911de mp911de self-assigned this Nov 5, 2025
@mp911de mp911de added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 5, 2025
@mp911de mp911de added this to the 4.4.12 (2024.1.12) milestone Nov 5, 2025
@mp911de
Copy link
Member

mp911de commented Nov 5, 2025

Thank you for your contribution. That's fixed slightly simpler along with a backport to 4.4.x and 4.5.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: task A general task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants