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

resteasy.plugins.providers.multipart.AbstractMultipartFormDataWriter could skip null attrbitues instead of throwing NPE

XMLWordPrintable

    • Icon: Feature Request Feature Request
    • Resolution: Done
    • Icon: Major Major
    • 1.0.2.GA
    • 1.0.1.GA
    • None

      Currently if I have a custom bean (MyBean) and I use it with MediaType.MULTIPART_FORM_DATA content type and MultipartForm annotation in a rest service (MyService.createMyBean()) if some property is null an NPE is thrown. I think with a small modification in resteasy.plugins.providers.multipart.AbstractMultipartFormDataWriter these null properties could be simply skipped. As in multipart/form-data every part has a name it's not a problem if some parts are not present.

      Suggested modification in resteasy.plugins.providers.multipart.AbstractMultipartFormDataWriter:
      protected void writeParts(MultipartOutput multipartOutput, OutputStream entityStream, byte[] boundaryBytes) throws IOException
      {
      MultipartFormDataOutput form = (MultipartFormDataOutput) multipartOutput;
      for (Map.Entry<String, OutputPart> entry : form.getFormData().entrySet())

      { + if (entry.getValue().getEntity() == null) + continue; MultivaluedMap<String, Object> headers = new MultivaluedMapImpl<String, Object>(); headers.putSingle("Content-Disposition", "form-data; name=\"" + entry.getKey() + "\""); writePart(entityStream, boundaryBytes, entry.getValue(), headers); }

      }

      MyBean.java:
      public class MyBean
      {
      @FormParam("someBinary")
      @PartType(MediaType.APPLICATION_OCTET_STREAM)
      private InputStream someBinary;

      public InputStream getSomeBinary()

      { return someBinary; }

      public void setSomeBinary(InputStream someBinary)

      { this.someBinary = someBinary; }

      }

      MyService.java:
      @Path("/mime")
      public class MyService
      {

      @GET
      @Produces(MediaType.MULTIPART_FORM_DATA)
      @MultipartForm
      public MyBean createMyBean()

      { MyBean myBean = new MyBean(); myBean.setSomeBinary(null); return myBean; }

      }

              patriot1burke@gmail.com Bill Burke (Inactive)
              akiraly Attila Király (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: