Home > Software engineering >  Java Rest Template throws java.lang.IllegalArgumentException: Comparison method violates its general
Java Rest Template throws java.lang.IllegalArgumentException: Comparison method violates its general

Time:09-29

I am not using any Comparators/Sorting in my Java code, still it is throwing " java.lang.IllegalArgumentException: Comparison method violates its general contract!" Exception.

Below is the piece of code that throws exception on the restTemplate.exchange line on debugging.

Started getting this exception when I changed the version of spring-boot-starter-parent from 2.3.9 to 2.5.3

How should I resolve this?

import org.springframework.web.client.RestTemplate;
Function call : AzureCredentials oStoreCreds = azureAutoConfiguration.getObjectStoreCreds(mop, new RestTemplate());

    @Bean
    @Profile("cf-azure")
    @Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
    public AzureCredentials getObjectStoreCreds(ManagedObjectStoreProperties mosp, RestTemplate restTemplate) {
    try {
            String managed_instance_url = mosp.getGet_managed_instance_url().replace("{tenant_id}", tenantId);
            HttpHeaders headers = new HttpHeaders();
            headers.setBasicAuth(mosp.getUser(), mosp.getPassword());
            HttpEntity<?> entity = new HttpEntity<>(null, headers);
            ResponseEntity<ManagedObjectStoreAzureClientResponse> response = restTemplate.exchange(managed_instance_url, HttpMethod.GET, entity, ManagedObjectStoreAzureClientResponse.class);
            azureCredentials = response.getBody().getCredentials();
        } catch (RestClientException exception) {
            LoggerHelper.logError(LoggerHelper.getLogger(this.getClass()), "Fetching managed object store credentials failed.");
        }catch (Exception e){
            LoggerHelper.logError(LoggerHelper.getLogger(this.getClass()), "Generic Exception - Fetching managed object store credentials failed.");
        }
   return azureCredentials;
    }

Stack Trace:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: Comparison method violates its general contract!] with root cause
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT java.lang.IllegalArgumentException: Comparison method violates its general contract!
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at java.util.TimSort.mergeHi(TimSort.java:899) ~[na:1.8.0_301]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at java.util.TimSort.mergeAt(TimSort.java:516) ~[na:1.8.0_301]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at java.util.TimSort.mergeCollapse(TimSort.java:441) ~[na:1.8.0_301]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at java.util.TimSort.sort(TimSort.java:245) ~[na:1.8.0_301]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at java.util.Arrays.sort(Arrays.java:1512) ~[na:1.8.0_301]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at java.util.ArrayList.sort(ArrayList.java:1464) ~[na:1.8.0_301]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.http.MediaType.sortBySpecificityAndQuality(MediaType.java:780) ~[spring-web-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:254) ~[spring-webmvc-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:219) ~[spring-webmvc-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:78) ~[spring-web-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:124) ~[spring-webmvc-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1064) ~[spring-webmvc-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) ~[tomcat-embed-core-9.0.50.jar:4.0.FR]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[tomcat-embed-core-9.0.50.jar:4.0.FR]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:228) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:190) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at com.sap.icd.mt.config.FilterConfig$1.doFilter(FilterConfig.java:36) ~[mt-spring-boot-starter-2.11.2-20200305172704.jar:na]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:190) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:327) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:81) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:121) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:126) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:81) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:105) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:149) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationFilter.doFilterInternal(BearerTokenAuthenticationFilter.java:137) ~[spring-security-oauth2-resource-server-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:103) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:89) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:117) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:110) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:80) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:55) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:211) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:183) ~[spring-security-web-5.5.1.jar:5.5.1]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358) ~[spring-web-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271) ~[spring-web-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:190) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:190) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:190) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.9.jar:5.3.9]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:190) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) [tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) [tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:769) [tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) [tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382) [tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893) [tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1723) [tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_301]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_301]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.50.jar:9.0.50]
   2021-09-28T19:56:56.86 0530 [APP/PROC/WEB/0] OUT     at java.lang.Thread.run(Thread.java:836) [na:1.8.0_301]

CodePudding user response:

The stacktrace indicates that for some reason the Comparator method for the MediaType.java class is not ok. As you pointed out that this seems to work locally but not in the cloud I would suggest you compare runtimes.

Looking through the source code for the AbstractMessageConverterMethodProcessor.java the sorting method is called when the content type for the response can not be found. Maybe you can force a content type by setting an accept header in the request. Assuming your expecting a JSON response:

headers.setAccept(List.of(MediaType.APPLICATION_JSON));

Not sure if this fixes it though, as I could not reproduce the issue in the first place.

CodePudding user response:

There should be some problem for the comparator QUALITY_VALUE_COMPARATOR inside MediaType.sortBySpecificityAndQuality, I am able to reproduce the exception with below program. A ticket is raised in github.

Run in Win 10 openjdk version "16" 2021-03-16

public class TestMediaTypeSort {
    public static void main(String[] args) {
        Map<String, String> mapSize1 = Map.of("a", "b");
        Map<String, String> mapSize2 = Map.of("a", "b", "c", "d");
        Map<String, String> mapSize3 = Map.of("a", "b", "c", "d", "e", "f");
        List<MediaType> mediaTypeList = new ArrayList<>();
        for (int i = 0; i < 20; i  ) {
            mediaTypeList.add(new MediaType("c", "a", mapSize1));
            mediaTypeList.add(new MediaType("c", "a", mapSize2));
            mediaTypeList.add(new MediaType("c", "a", mapSize3));
            mediaTypeList.add(new MediaType("b", "a", mapSize1));
            mediaTypeList.add(new MediaType("b", "a", mapSize2));
            mediaTypeList.add(new MediaType("b", "a", mapSize3));
            mediaTypeList.add(new MediaType("b", "a", mapSize2));
        }
        MediaType.sortBySpecificityAndQuality(mediaTypeList);
    }
}
  • Related