Skip to content

Conversation

@prathyushreddylpr
Copy link
Owner

Description

Fixed the flaky test extendedXmlJavaTypeAdapter and simpleXmlJavaTypeAdapter inside JAXBUtilsTest.java class.

Root Cause

The tests extendedXmlJavaTypeAdapter and simpleXmlJavaTypeAdapter have been reported flaky when run with the NonDex tool. The tests failed due to the non-deterministic ordering of fields returned by getDeclaredFields(). The getDeclaredFields() method returns an array of Field objects representing all the fields declared by a class or interface. In the above tests, it returned two values: one a private field named birthDate of type java.time.LocalDate and the other org.apache.cxf.jaxrs.utils.JAXBUtilsTest$CustomerDetailsWithExtendedAdapter.this$0. The second value represents a synthetic field generated by the Java compiler for the inner class CustomerDetailsWithExtendedAdapter. When an inner class accesses members of its enclosing class, Java creates a synthetic field (in this case, this$0) as a reference to the outer class (JAXBUtilsTest) which is not useful for the test.

Fix

To ensure the tests are not flaky due to the non-deterministic ordering of fields returned by getDeclaredFields(), we introduced a condition to filter out the fields(synthetic and final fields) that are not useful for the testing.

How this has been tested?

Java: openjdk version "17.0.8"
Maven: Apache Maven 3.6.3

  1. Module build - Successful
    Command used -
mvn install -pl core -am -DskipTests
  1. Regular test - Successful
    Commands used -
mvn -pl rt/frontend/jaxrs/ -Dtest=org.apache.cxf.jaxrs.utils.JAXBUtilsTest#extendedXmlJavaTypeAdapter
mvn -pl rt/frontend/jaxrs/ -Dtest=org.apache.cxf.jaxrs.utils.JAXBUtilsTest#simpleXmlJavaTypeAdapter
  1. NonDex test - Failed
    Command used -
mvn -pl rt/frontend/jaxrs/ edu.illinois:nondex-maven-plugin:2.1.7-SNAPSHOT:nondex -Dtest=org.apache.cxf.jaxrs.utils.JAXBUtilsTest#extendedXmlJavaTypeAdapter
mvn -pl rt/frontend/jaxrs/ edu.illinois:nondex-maven-plugin:2.1.7-SNAPSHOT:nondex -Dtest=org.apache.cxf.jaxrs.utils.JAXBUtilsTest#simpleXmlJavaTypeAdapter

NonDex test passed after the fix.

@zzjas
Copy link

zzjas commented Nov 29, 2023

LGTM

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.

2 participants