Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-728

MimeHeaders.setValue throws NPE when IOUtils.copy is called

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Bug
    • 2.5
    • None
    • Utilities
    • None
    • Java Version: 1.8

      Spring version: 4.3.11.RELEASE

      Spring boot version: 2.0.5.RELEASE

      Jersey version: 2.16

    Description

      I have a Spring Boot Microservice and I am using IOUtils.copy(InputStream, OutputStream) which sporadically throws NPE while setting MimeHeaders as shown below:

      2021-03-18 18:14:05.081 ERROR [http-nio-80-exec-8] o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] threw exception2021-03-18 18:14:05.081 ERROR [http-nio-80-exec-8] o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] threw exception
      java.lang.NullPointerException: null at
      org.apache.tomcat.util.http.MimeHeaders.setValue(MimeHeaders.java:318) at org.apache.coyote.http11.Http11Processor.prepareResponse(Http11Processor.java:1285) at org.apache.coyote.AbstractProcessor.action(AbstractProcessor.java:374) at org.apache.coyote.Response.action(Response.java:206) at org.apache.coyote.http11.Http11OutputBuffer.doWrite(Http11OutputBuffer.java:219) at org.apache.coyote.Response.doWrite(Response.java:602) at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:352) at org.apache.catalina.connector.OutputBuffer.flushByteBuffer(OutputBuffer.java:833) at org.apache.catalina.connector.OutputBuffer.append(OutputBuffer.java:738) at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:399) at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:377) at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:96) at org.springframework.security.web.util.OnCommittedResponseWrapper$SaveContextServletOutputStream.write(OnCommittedResponseWrapper.java:639) at
      org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2147) at
      org.apache.commons.io.IOUtils.copy(IOUtils.java:2102) at
      org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:2123) at
      org.apache.commons.io.IOUtils.copy(IOUtils.java:2078)

      I have attached the complete stack trace in the attachment and also provided the environment where this appears.
      I feel that there is some issue with the Commons IO lib and would like to know if this can be fixed.

      My application has the following code to which the stack trace points to:

      FileInputStream fis = new FileInputStream(tempOutputFile);
      return outputStream -> { IOUtils.copy(fis, outputStream); }

      ;

      Found the page http://tomcat.10.x6.nabble.com/NullPointerException-in-MimeHeaders-td2054107.html which talks about a similar problem and coincidentally we too use org.apache.catalina.connector.RECYCLE_FACADES=true system property to avoid reuse of request and response objects, but it isn't not working for us as well.
       

      Attachments

        1. StackTrace
          18 kB
          Anuj PB

        Activity

          People

            Unassigned Unassigned
            anuj_pb Anuj PB
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: