java.lang.UnsupportedOperationException: null

Spring JIRA | Toshiaki Maki | 3 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Writing Protobuf as response body doesn't work with default settings because {{ProtobufHttpMessageConverter}} attempt to write HTTP header of read-only {{ServletServerHttpResponse}}. As the result, the following exeception is thrown after HTTP request: {code} java.lang.UnsupportedOperationException: null at java.util.Collections$UnmodifiableMap.put(Collections.java:1517) at org.springframework.http.HttpHeaders.set(HttpHeaders.java:869) at org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter.setProtoHeader(ProtobufHttpMessageConverter.java:196) at org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter.writeInternal(ProtobufHttpMessageConverter.java:182) at org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter.writeInternal(ProtobufHttpMessageConverter.java:60) at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:208) at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:153) at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:97) at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:202) at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:71) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:122) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) at javax.servlet.http.HttpServlet.service(HttpServlet.java:620) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1695) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) {code} Current {{ProtobufHttpMessageConverter}} implementation is like: {code:java} @Override protected void writeInternal(Message message, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { // ... ommited OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(), charset); // <-- (1) if (MediaType.TEXT_HTML.isCompatibleWith(contentType)) { HtmlFormat.print(message, writer); } // ... ommited else if (PROTOBUF.isCompatibleWith(contentType)) { setProtoHeader(outputMessage, message); // <-- (2) FileCopyUtils.copy(message.toByteArray(), outputMessage.getBody()); } } private void setProtoHeader(HttpOutputMessage response, Message message) { response.getHeaders().set(X_PROTOBUF_SCHEMA_HEADER, message.getDescriptorForType().getFile().getName()); response.getHeaders().set(X_PROTOBUF_MESSAGE_HEADER, message.getDescriptorForType().getFullName()); } {code} At (1) {{outputMessage.getBody()}} makes {{headersWritten}} field {{true}} and {{headers}} field read-only in {{ServletServerHttpResponse}}. At (2) Header is set in spite of the {{headers}} is already read-only. Actually, customized {{ProtobufHttpMessageConverter}} works well like: {code:java} ProtobufHttpMessageConverter protobufHttpMessageConverter = new ProtobufHttpMessageConverter((registry) -> { }) { @Override protected void writeInternal(Message message, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { outputMessage.getHeaders().set(X_PROTOBUF_SCHEMA_HEADER, message.getDescriptorForType().getFile().getName()); outputMessage.getHeaders().set(X_PROTOBUF_MESSAGE_HEADER, message.getDescriptorForType().getFullName()); FileCopyUtils.copy(message.toByteArray(), outputMessage.getBody()); } }; {code}

    Spring JIRA | 3 years ago | Toshiaki Maki
    java.lang.UnsupportedOperationException: null
  2. 0

    Writing Protobuf as response body doesn't work with default settings because {{ProtobufHttpMessageConverter}} attempt to write HTTP header of read-only {{ServletServerHttpResponse}}. As the result, the following exeception is thrown after HTTP request: {code} java.lang.UnsupportedOperationException: null at java.util.Collections$UnmodifiableMap.put(Collections.java:1517) at org.springframework.http.HttpHeaders.set(HttpHeaders.java:869) at org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter.setProtoHeader(ProtobufHttpMessageConverter.java:196) at org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter.writeInternal(ProtobufHttpMessageConverter.java:182) at org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter.writeInternal(ProtobufHttpMessageConverter.java:60) at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:208) at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:153) at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:97) at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:202) at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:71) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:122) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) at javax.servlet.http.HttpServlet.service(HttpServlet.java:620) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1695) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) {code} Current {{ProtobufHttpMessageConverter}} implementation is like: {code:java} @Override protected void writeInternal(Message message, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { // ... ommited OutputStreamWriter writer = new OutputStreamWriter(outputMessage.getBody(), charset); // <-- (1) if (MediaType.TEXT_HTML.isCompatibleWith(contentType)) { HtmlFormat.print(message, writer); } // ... ommited else if (PROTOBUF.isCompatibleWith(contentType)) { setProtoHeader(outputMessage, message); // <-- (2) FileCopyUtils.copy(message.toByteArray(), outputMessage.getBody()); } } private void setProtoHeader(HttpOutputMessage response, Message message) { response.getHeaders().set(X_PROTOBUF_SCHEMA_HEADER, message.getDescriptorForType().getFile().getName()); response.getHeaders().set(X_PROTOBUF_MESSAGE_HEADER, message.getDescriptorForType().getFullName()); } {code} At (1) {{outputMessage.getBody()}} makes {{headersWritten}} field {{true}} and {{headers}} field read-only in {{ServletServerHttpResponse}}. At (2) Header is set in spite of the {{headers}} is already read-only. Actually, customized {{ProtobufHttpMessageConverter}} works well like: {code:java} ProtobufHttpMessageConverter protobufHttpMessageConverter = new ProtobufHttpMessageConverter((registry) -> { }) { @Override protected void writeInternal(Message message, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { outputMessage.getHeaders().set(X_PROTOBUF_SCHEMA_HEADER, message.getDescriptorForType().getFile().getName()); outputMessage.getHeaders().set(X_PROTOBUF_MESSAGE_HEADER, message.getDescriptorForType().getFullName()); FileCopyUtils.copy(message.toByteArray(), outputMessage.getBody()); } }; {code}

    Spring JIRA | 3 years ago | Toshiaki Maki
    java.lang.UnsupportedOperationException: null
  3. 0

    Exchanging data between steps in spring batch

    Stack Overflow | 3 years ago | Noa Drach
    java.lang.UnsupportedOperationException: null
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Putting into the jobExecutionContext - UnsupportedOperationException

    Stack Overflow | 9 months ago | Richie
    java.lang.UnsupportedOperationException: null
  6. 0

    spring mvc http proxy

    Stack Overflow | 2 years ago | C.Giraud
    java.lang.UnsupportedOperationException
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.UnsupportedOperationException

    null

    at java.util.Collections$UnmodifiableMap.put()
  2. Java RT
    Collections$UnmodifiableMap.put
    1. java.util.Collections$UnmodifiableMap.put(Collections.java:1517)
    1 frame
  3. Spring
    HttpHeaders.set
    1. org.springframework.http.HttpHeaders.set(HttpHeaders.java:869)
    1 frame
  4. org.springframework.http
    ProtobufHttpMessageConverter.writeInternal
    1. org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter.setProtoHeader(ProtobufHttpMessageConverter.java:196)
    2. org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter.writeInternal(ProtobufHttpMessageConverter.java:182)
    3. org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter.writeInternal(ProtobufHttpMessageConverter.java:60)
    3 frames
  5. Spring
    AbstractHttpMessageConverter.write
    1. org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:208)
    1 frame
  6. Spring MVC
    RequestResponseBodyMethodProcessor.handleReturnValue
    1. org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:153)
    2. org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:97)
    3. org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:202)
    3 frames
  7. Spring
    HandlerMethodReturnValueHandlerComposite.handleReturnValue
    1. org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:71)
    1 frame
  8. Spring MVC
    FrameworkServlet.doGet
    1. org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:122)
    2. org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781)
    3. org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
    4. org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    5. org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
    6. org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    7. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    8. org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
    8 frames
  9. JavaServlet
    HttpServlet.service
    1. javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    1 frame
  10. Spring MVC
    FrameworkServlet.service
    1. org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    1 frame
  11. JavaServlet
    HttpServlet.service
    1. javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    1 frame
  12. Glassfish Core
    ApplicationFilterChain.doFilter
    1. org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    2. org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    2 frames
  13. Spring
    OncePerRequestFilter.doFilter
    1. org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    2. org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    2 frames
  14. Glassfish Core
    CoyoteAdapter.service
    1. org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    2. org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    3. org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    4. org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    5. org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    6. org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
    7. org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    8. org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    9. org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    10. org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    10 frames
  15. Grizzly HTTP
    NioEndpoint$SocketProcessor.run
    1. org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    2. org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    3. org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736)
    4. org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1695)
    4 frames
  16. Java RT
    ThreadPoolExecutor$Worker.run
    1. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    2. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    2 frames
  17. Tomcat Util
    TaskThread$WrappingRunnable.run
    1. org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    1 frame
  18. Java RT
    Thread.run
    1. java.lang.Thread.run(Thread.java:745)
    1 frame