Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-3521

java.lang.IllegalArgumentException: Comparison method violates its general contract! thrown in sort

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Major Major
    • None
    • None
    • Core
    • None

      There is an error that seems to get triggered with the test in https://github.com/resteasy/resteasy/pull/4251/. This produces the following error:

      jakarta.ws.rs.ProcessingException: java.lang.IllegalArgumentException: Comparison method violates its general contract!
      	at org.jboss.resteasy.resteasy-client@7.0.0.Alpha3-SNAPSHOT//org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:219)
      	at org.jboss.resteasy.resteasy-core@7.0.0.Alpha3-SNAPSHOT//org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:75)
      	at org.jboss.resteasy.resteasy-client@7.0.0.Alpha3-SNAPSHOT//org.jboss.resteasy.client.jaxrs.internal.AbortedResponse.readEntity(AbortedResponse.java:96)
      	at org.jboss.resteasy.resteasy-core@7.0.0.Alpha3-SNAPSHOT//org.jboss.resteasy.specimpl.AbstractBuiltResponse.readEntity(AbstractBuiltResponse.java:232)
      	at deployment.5ea90e63-d814-4f78-a081-e7de1b657c4c.war//org.jboss.resteasy.test.cdi.context.InjectedProviderClientTest.contextResolverInjected(InjectedProviderClientTest.java:102)
      	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
      	at deployment.5ea90e63-d814-4f78-a081-e7de1b657c4c.war//org.jboss.arquillian.junit5.ArquillianExtension.interceptTestMethod(ArquillianExtension.java:87)
      	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
      	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
      Caused by: java.lang.IllegalArgumentException: Comparison method violates its general contract!
      	at java.base/java.util.TimSort.mergeHi(TimSort.java:903)
      	at java.base/java.util.TimSort.mergeAt(TimSort.java:520)
      	at java.base/java.util.TimSort.mergeCollapse(TimSort.java:448)
      	at java.base/java.util.TimSort.sort(TimSort.java:245)
      	at java.base/java.util.Arrays.sort(Arrays.java:1307)
      	at java.base/java.util.ArrayList.sort(ArrayList.java:1721)
      	at java.base/java.util.Collections.sort(Collections.java:179)
      	at org.jboss.resteasy.resteasy-core@7.0.0.Alpha3-SNAPSHOT//org.jboss.resteasy.core.MediaTypeMap.getPossible(MediaTypeMap.java:561)
      	at org.jboss.resteasy.resteasy-core@7.0.0.Alpha3-SNAPSHOT//org.jboss.resteasy.core.providerfactory.ResteasyProviderFactoryImpl.resolveMessageBodyReader(ResteasyProviderFactoryImpl.java:558)
      	at org.jboss.resteasy.resteasy-core@7.0.0.Alpha3-SNAPSHOT//org.jboss.resteasy.core.providerfactory.ResteasyProviderFactoryImpl.getClientMessageBodyReader(ResteasyProviderFactoryImpl.java:550)
      	at org.jboss.resteasy.resteasy-core@7.0.0.Alpha3-SNAPSHOT//org.jboss.resteasy.core.interception.jaxrs.ClientReaderInterceptorContext.resolveReader(ClientReaderInterceptorContext.java:52)
      	at org.jboss.resteasy.resteasy-core@7.0.0.Alpha3-SNAPSHOT//org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:127)
      	at org.jboss.resteasy.resteasy-core@7.0.0.Alpha3-SNAPSHOT//org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:76)
      	at org.jboss.resteasy.resteasy-crypto@7.0.0.Alpha3-SNAPSHOT//org.jboss.resteasy.security.doseta.DigitalVerificationInterceptor.aroundReadFrom(DigitalVerificationInterceptor.java:32)
      	at org.jboss.resteasy.resteasy-core@7.0.0.Alpha3-SNAPSHOT//org.jboss.resteasy.core.interception.jaxrs.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:89)
      	at org.jboss.resteasy.resteasy-client@7.0.0.Alpha3-SNAPSHOT//org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:192)
      	... 8 more
      

      The sorting code has not changed in 15 years. I'm not too sure why this is being seen only here. A guess would be because the test uses the ClientRequestContext.abortWith() method.

      I can see some potential where the comparison breaks the compareTo contract. However, some better analysis needs to be done. The spec reference can be found at https://jakarta.ee/specifications/restful-ws/4.0/jakarta-restful-ws-spec-4.0#message_body_writer. A reader likely has the same issue.

              Unassigned Unassigned
              jperkins-rhn James Perkins
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: