Java Rest Template throws java.lang.IllegalArgumentException: 比较方法违反了它的通用契约
Java Rest Template throws java.lang.IllegalArgumentException: Comparison method violates its general contract
我没有在我的 Java 代码中使用任何 Comparators/Sorting,它仍然抛出“java.lang.IllegalArgumentException:比较方法违反了它的一般性合同!”异常。
下面是调试时在 restTemplate.exchange 行抛出异常的代码。
当我将 spring-boot-starter-parent 的版本从 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.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]
堆栈跟踪表明由于某种原因,MediaType.java
class 的 Comparator 方法不正确。正如您所指出的,这似乎在本地有效,但在云中无效,我建议您比较运行时间。
查看 AbstractMessageConverterMethodProcessor.java
的源代码,当找不到响应的内容类型时调用排序方法。也许您可以通过在请求中设置 accept
header 来强制内容类型。假设您期待 JSON 响应:
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
不确定这是否解决了问题,因为我一开始无法重现该问题。
在 github 中提出 the comparator QUALITY_VALUE_COMPARATOR inside MediaType.sortBySpecificityAndQuality
, I am able to reproduce the exception with below program. A ticket 应该有一些问题。
运行 在 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);
}
}
我没有在我的 Java 代码中使用任何 Comparators/Sorting,它仍然抛出“java.lang.IllegalArgumentException:比较方法违反了它的一般性合同!”异常。
下面是调试时在 restTemplate.exchange 行抛出异常的代码。
当我将 spring-boot-starter-parent 的版本从 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.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]
堆栈跟踪表明由于某种原因,MediaType.java
class 的 Comparator 方法不正确。正如您所指出的,这似乎在本地有效,但在云中无效,我建议您比较运行时间。
查看 AbstractMessageConverterMethodProcessor.java
的源代码,当找不到响应的内容类型时调用排序方法。也许您可以通过在请求中设置 accept
header 来强制内容类型。假设您期待 JSON 响应:
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
不确定这是否解决了问题,因为我一开始无法重现该问题。
在 github 中提出 the comparator QUALITY_VALUE_COMPARATOR inside MediaType.sortBySpecificityAndQuality
, I am able to reproduce the exception with below program. A ticket 应该有一些问题。
运行 在 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);
}
}