primefaces / primefaces

Ultimate Component Suite for JavaServer Faces
http://www.primefaces.org
MIT License
1.77k stars 752 forks source link

FileUpload: several NPEs #7617

Closed wal-jan closed 3 years ago

wal-jan commented 3 years ago

Follow up of #6428 FileUpload throws NPE at several places. <p:fileUpload mode=simple auto=true fileLimit=x sizeLimit=y allowTypes=z .../> sends empty parts if fileLimit, sizeLimit or allowTypes are violated. NPEs occur with both UPLOADER=native and UPLOADER=commons Example:

java.lang.NullPointerException
        at org.primefaces.model.file.NativeUploadedFile.getSize(NativeUploadedFile.java:70)
        at org.primefaces.model.file.UploadedFileWrapper.getSize(UploadedFileWrapper.java:74)
        at org.primefaces.util.FileUploadUtils.tryValidateFile(FileUploadUtils.java:299)
        at org.primefaces.component.fileupload.FileUpload.validateValue(FileUpload.java:85)
        at javax.faces.component.UIInput.validate(UIInput.java:1021)
        at javax.faces.component.UIInput.executeValidate(UIInput.java:1318)
        at javax.faces.component.UIInput.processValidators(UIInput.java:733)
        at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:608)
        at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:159)
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:1456)
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
        at javax.faces.component.UIForm.visitTree(UIForm.java:355)
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
        at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:400)
        at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:261)
        at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:65)
        at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:65)
        at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1308)
        at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:53)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:76)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:177)
        at javax.faces.lifecycle.LifecycleWrapper.execute(LifecycleWrapper.java:73)
        at javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:707)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)
java.lang.NullPointerException
        at org.primefaces.component.fileupload.CommonsFileUploadDecoder.createUploadedFile(CommonsFileUploadDecoder.java:53)
        at org.primefaces.component.fileupload.CommonsFileUploadDecoder.createUploadedFile(CommonsFileUploadDecoder.java:36)
        at org.primefaces.component.fileupload.AbstractFileUploadDecoder.decodeSimple(AbstractFileUploadDecoder.java:75)
        at org.primefaces.component.fileupload.AbstractFileUploadDecoder.decode(AbstractFileUploadDecoder.java:51)
        at org.primefaces.component.fileupload.FileUploadRenderer.decode(FileUploadRenderer.java:64)
        at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:509)
        at javax.faces.component.UIInput.decode(UIInput.java:798)
        at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:886)
        at javax.faces.component.UIInput.processDecodes(UIInput.java:692)
        at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:606)
        at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:159)
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:1456)
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
        at javax.faces.component.UIForm.visitTree(UIForm.java:355)
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
        at javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
        at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:400)
        at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:261)
        at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:65)
        at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:65)
        at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:1008)
        at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:55)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:76)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:177)
        at javax.faces.lifecycle.LifecycleWrapper.execute(LifecycleWrapper.java:73)
        at javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:707)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)

Reproducer PF-6428-native.zip PF-6428-commons.zip

Environment:

To Reproduce Steps to reproduce the behavior:

  1. Go to 'http://localhost:8080/primefaces-test/'
  2. Chose file/files wich violate description above the widget
  3. See error in log file (in GUI no error is shown)

Expected behavior No NPEs in log.

Example XHTML

<h:form id="frmTest">
   <p:fileUpload mode="simple" skinSimple="true" auto="true" fileLimit=x sizeLimit=y allowTypes=z />
</h:form>

Example Bean see reproducer

(I've created some more FileUpload integration tests where I stumbled across the NPEs. I'll create a PR if these tests are somewhat stable. But that's not the case yet.)

melloware commented 3 years ago

OK I fixed the first one with this PR: https://github.com/primefaces/primefaces/pull/7618