cayenne
cayenne copied to clipboard
Fix get declared fields dependent test
Description
Test org.apache.cayenne.reflect.PojoMapperTest.testObjectCreation will fail under NonDex which detects flakiness under non-deterministic environment.
To reproduce:
mvn edu.illinois:nondex-maven-plugin:1.1.2:nondex \
-pl cayenne-server \
-Dtest=org.apache.cayenne.reflect.PojoMapperTest#testObjectCreation
Issue
In testObjectCreation, the object creation depends on the following logic:
Field[] declaredFields = type.getDeclaredFields();
this.setters = new MethodHandle[declaredFields.length];
int i = 0;
for(Field field : declaredFields) {
...
setters[i++] = lookup.unreflectSetter(field);
}
However, according to the documentation of getDeclaredFields, the function does not guarantee the order of fields and may be different on different JVM.
Simply applying sorting on the fields could guarantee correctness in the testing environment.