cayenne icon indicating copy to clipboard operation
cayenne copied to clipboard

Fix get declared fields dependent test

Open shunfan-shao opened this issue 4 years ago • 0 comments

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.

shunfan-shao avatar Nov 23 '21 02:11 shunfan-shao