当前位置: 首页 > 知识库问答 >
问题:

Java Rest Template抛出Java.lang.IllegalArgumentException:比较方法违反了其一般约定

邹锦
2023-03-14

我在Java代码中没有使用任何Comparator/Sorting,它仍然抛出“Java.lang.IllegalArgumentException:Comparison方法违反了它的一般约定!”例外

下面是调试时在restTemplate.exchange行抛出异常的一段代码。

当我将springbootstarter父版本从2.3.9更改为2.5.3时,开始出现此异常

我应该如何解决这个问题?

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;
    }

堆栈跟踪:

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]

共有2个答案

弓明亮
2023-03-14

MediaType.sortBySpecificityAndQuality内部的比较器QUALITY_VALUE_COMPARATOR应该存在一些问题,我能够使用以下程序重现异常。在 github 中提出了一张票证。

运行于Win 10 openjdk版本“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);
    }
}
山森
2023-03-14

堆栈跟踪表明由于某种原因MediaType.java类的比较器方法不好。正如您指出的,这似乎在本地工作,但在云中不起作用,我建议您比较运行时。

查看 AbstractMessageConverterMethodProcessor 的源代码.java当找不到响应的内容类型时,将调用排序方法。也许您可以通过在请求中设置接受标头来强制使用内容类型。假设您期望收到 JSON 响应:

< code > headers . set accept(list . of(media type。APPLICATION _ JSON));

不确定这是否修复了它,因为我不能在第一个地方重现这个问题。

 类似资料:
  • 以下几行: 返回以下异常:比较方法违反了其一般约定! 我知道这个异常通常是在没有正确实现比较方法时产生的,但是在我的例子中,它的实现是相当明显的: 正如您所看到的,目标是按照值的hashValue属性对值进行排序。 任何关于我做错了什么的想法/提示将不胜感激! 谢谢托马斯

  • 问题内容: 您好,以下是我的比较器的比较方法。我不确定是什么问题。我在堆栈溢出时查找了其他类似标题的问题和答案,但不确定我的方法有什么问题,但我一直在获取java.lang.IllegalArgumentException:比较方法违反了它的一般约定! 任何帮助将不胜感激 添加我得到的异常 问题答案: 您的方法 不是可 传递的 。如果和,则必须等于。 现在考虑这种情况: 对于,和,假设方法返回以下

  • 我所拥有的 我有此代码,用于根据名称,日期或大小对文件进行排序。 但我得到了这个错误, 我的一些用户得到了这个错误,我在崩溃报告中看到了它。但我自己无法以任何方式重现这个错误。 任何人都可以帮助我找到问题。我似乎真的花了很多时间,但找不到任何东西。请帮我吗? 提前谢谢。

  • 可能的重复: 为什么我的比较方法会抛出异常 — 比较方法违反了其一般合同! 我有这个代码: 有时它会引发以下异常: 为什么? 1) 我该如何避免呢?2) 我怎么能抓住这个例外? 提前谢谢。

  • 我想通过dateLastContact比较两个“收件人”,如果相同,就通过地址进行比较。这是我的代码: 而且我总是有这个错误: 我尝试了很多方法,但是现在,我不知道该怎么办。你能帮我吗? 收件人类别:

  • 嗨,下面是我的比较器的比较方法。我不知道哪里出了问题。我查了关于堆栈溢出的其他类似标题的问题和答案,但不确定我的方法有什么问题,但我不断得到java.lang.IllegalArgument异常:比较方法违反了它的一般合同! 任何帮助将不胜感激 添加我得到的异常