Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-2385

NullPointerException on MultipartInputImpl.PartImpl::getBody with MultipartRelatedInput as type

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 4.5.5.Final
    • 3.7.0.Final
    • None

      Created a resource that is returning a Response object with MIME-type multipart/mixed. Response objects entity is a MultipartOutput object with multiple parts which themselves are MultipartRelatedOutput objects:

      @GET
      @Path("test")
      @Produces("multipart/mixed")
      public Response test() {
        ...
        final MultipartOutput multipartOutput = new MultipartOutput();
        entities.stream().map(entity -> {
          MultipartRelatedOutput multipartRelatedOutput = new MultipartRelatedOutput();
          multipartRelatedOutput.addPart(entity, MediaType.APPLICATION_JSON_TYPE);
          return multipartRelatedOutput;
        }).forEach(multipartRelatedOutput -> 
          multipartOutput.addPart(multipartRelatedOutput, MediaType.valueOf("multipart/related"))
        );
        return Response.ok(multipartOutput, MediaType.valueOf("multipart/mixed")).build();
      }
      

      This resource is consumed by client via RESTEasy proxy framework. The Response entity is read as MultipartInput. Each parts body should now be read as MultipartRelatedInput which throws a NullPointerException:

      public void get()
      {
        try (Response response = this.proxy.test();) {
          ...
          MultipartInput multipartInput = response.readEntity(MultipartInput.class);
          for (InputPart inputPart : multipartInput.getParts()) {
          try {
            MultipartRelatedInput relatedInput = inputPart.getBody(MultipartRelatedInput.class, null);
          } catch (IOException exception) {}
        }
      }
      
      Caused by: java.lang.NullPointerException
      	at java.base/java.io.SequenceInputStream.peekNextStream(SequenceInputStream.java:104)
      	at java.base/java.io.SequenceInputStream.nextStream(SequenceInputStream.java:97)
      	at java.base/java.io.SequenceInputStream.read(SequenceInputStream.java:203)
      	at org.apache.james.mime4j@0.6//org.apache.james.mime4j.io.BufferedLineReaderInputStream.fillBuffer(BufferedLineReaderInputStream.java:94)
      	at org.apache.james.mime4j@0.6//org.apache.james.mime4j.io.MimeBoundaryInputStream.fillBuffer(MimeBoundaryInputStream.java:196)
      	at org.apache.james.mime4j@0.6//org.apache.james.mime4j.io.MimeBoundaryInputStream.<init>(MimeBoundaryInputStream.java:75)
      	at org.apache.james.mime4j@0.6//org.apache.james.mime4j.parser.MimeEntity.createMimeStream(MimeEntity.java:217)
      	at org.apache.james.mime4j@0.6//org.apache.james.mime4j.parser.MimeEntity.advance(MimeEntity.java:152)
      	at org.apache.james.mime4j@0.6//org.apache.james.mime4j.parser.MimeTokenStream.next(MimeTokenStream.java:356)
      	at org.apache.james.mime4j@0.6//org.apache.james.mime4j.parser.MimeStreamParser.parse(MimeStreamParser.java:144)
      	at org.jboss.resteasy.resteasy-multipart-provider@3.7.0.Final//org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl$BinaryMessage.<init>(MultipartInputImpl.java:184)
      	at org.jboss.resteasy.resteasy-multipart-provider@3.7.0.Final//org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl$BinaryMessage.<init>(MultipartInputImpl.java:169)
      	at org.jboss.resteasy.resteasy-multipart-provider@3.7.0.Final//org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl.parse(MultipartInputImpl.java:235)
      	at org.jboss.resteasy.resteasy-multipart-provider@3.7.0.Final//org.jboss.resteasy.plugins.providers.multipart.MultipartRelatedInputImpl.parse(MultipartRelatedInputImpl.java:35)
      	at org.jboss.resteasy.resteasy-multipart-provider@3.7.0.Final//org.jboss.resteasy.plugins.providers.multipart.MultipartRelatedReader.readFrom(MultipartRelatedReader.java:49)
      	at org.jboss.resteasy.resteasy-multipart-provider@3.7.0.Final//org.jboss.resteasy.plugins.providers.multipart.MultipartRelatedReader.readFrom(MultipartRelatedReader.java:26)
      	at org.jboss.resteasy.resteasy-multipart-provider@3.7.0.Final//org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl$PartImpl.getBody(MultipartInputImpl.java:344)
      

      Getting the parts bodies as MultipartInput works. If MultipartRelatedInput is not supported exception should be thrown.

              rsearls r searls
              christian.schlegel Christian Schlegel (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: