Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-30272

Make the operation Document.GetBlobsByProperty ignore null blobs

    XMLWordPrintable

    Details

      Description

      Because of a previous bug when an entry was removed from a multi-valued field, it's possible to have the metadata files:files with a content like

      "files:files": [
            {
              "file": null
            },
            {
              "file": {
                "name": "017_B.pdf",
                "mime-type": "application/pdf",
                "encoding": null,
                "digestAlgorithm": "MD5",
                "digest": "76ce3452f72f774a774750a8788f9adf",
                "length": "185182",
                "data": "https://server/nuxeo/nxfile/default/84064f60-6ef6-420e-b3a7-ad7cbefcc378/files:files/1/file/017_B.pdf?changeToken=44-1"
              }
            },
            {
              "file": {
                "name": "VSO.pdf",
                "mime-type": "application/pdf",
                "encoding": null,
                "digestAlgorithm": "MD5",
                "digest": "c72cace463743b30ff8ce2daf8cfc617",
                "length": "3849135",
                "data": "https://server/nuxeo/nxfile/default/84064f60-6ef6-420e-b3a7-ad7cbefcc378/files:files/2/file/VSO.pdf?changeToken=44-1"
              }
            }
          ],
      

      JSF UI and Web UI correctly handles this state, but the operation Document.GetBlobsByProperty throws a NPE

      ERROR [http-nio-0.0.0.0-8080-exec-304] [org.nuxeo.ecm.webengine.app.WebEngineExceptionMapper] java.lang.NullPointerException
      java.lang.NullPointerException: null
      	at org.nuxeo.ecm.automation.jaxrs.io.documents.MultipartBlobs.addBlob(MultipartBlobs.java:60) ~[nuxeo-automation-io-10.10-HF27.jar:?]
      	at org.nuxeo.ecm.automation.jaxrs.io.documents.MultipartBlobs.addBlobs(MultipartBlobs.java:54) ~[nuxeo-automation-io-10.10-HF27.jar:?]
      	at org.nuxeo.ecm.automation.jaxrs.io.documents.MultipartBlobs.<init>(MultipartBlobs.java:49) ~[nuxeo-automation-io-10.10-HF27.jar:?]
      	at org.nuxeo.ecm.automation.server.jaxrs.ResponseHelper.blobs(ResponseHelper.java:83) ~[nuxeo-automation-server-10.10-HF29.jar:?]
      	at org.nuxeo.ecm.automation.server.jaxrs.ResponseHelper.blobs(ResponseHelper.java:76) ~[nuxeo-automation-server-10.10-HF29.jar:?]
      	at org.nuxeo.ecm.automation.server.jaxrs.ResponseHelper.getResponse(ResponseHelper.java:110) ~[nuxeo-automation-server-10.10-HF29.jar:?]
      	at org.nuxeo.ecm.automation.server.jaxrs.ExecutableResource.doPost(ExecutableResource.java:72) ~[nuxeo-automation-server-10.10-HF29.jar:?]
      

       

      This NPE can be easily avoided with a small change like

      --- a/nuxeo-features/nuxeo-automation/nuxeo-automation-io/src/main/java/org/nuxeo/ecm/automation/jaxrs/io/documents/MultipartBlobs.java
      +++ b/nuxeo-features/nuxeo-automation/nuxeo-automation-io/src/main/java/org/nuxeo/ecm/automation/jaxrs/io/documents/MultipartBlobs.java
      @@ -30,6 +30,8 @@ import javax.mail.internet.MimeMultipart;
       import javax.ws.rs.core.MediaType;
       import javax.ws.rs.core.Response;
       
      +import org.apache.commons.logging.Log;
      +import org.apache.commons.logging.LogFactory;
       import org.nuxeo.ecm.automation.jaxrs.io.InputStreamDataSource;
       import org.nuxeo.ecm.core.api.Blob;
       
      @@ -39,6 +41,8 @@ import org.nuxeo.ecm.core.api.Blob;
       public class MultipartBlobs extends MimeMultipart {
       
           private static final Pattern BOUNDARY = Pattern.compile(";\\s*boundary\\s*=\"([^\"]+)\"");
      +    
      +    private static final Log log = LogFactory.getLog(MultipartBlobs.class);
       
           public MultipartBlobs() {
               super("mixed");
      @@ -51,7 +55,11 @@ public class MultipartBlobs extends MimeMultipart {
       
           public void addBlobs(List<Blob> blobs) throws MessagingException, IOException {
               for (Blob blob : blobs) {
      -            addBlob(blob);
      +            if (blob != null) {
      +                addBlob(blob);
      +            } else {
      +                log.error("Skipping null blob");
      +            }
               }
           } 

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              tmartins Thierry Martins
              Participants:
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: