question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FileUpload: throws RuntimeExceptions when chunked mode is used

See original GitHub issue

Describe the defect

  1. Chunked FileUpload throws RuntimeException if UPLOADER=native.
java.util.NoSuchElementException
at java.base/java.util.HashMap$HashIterator.nextNode(HashMap.java:1495)
at java.base/java.util.HashMap$KeyIterator.next(HashMap.java:1516)
at java.base/java.util.Collections$3.nextElement(Collections.java:5267)
at org.primefaces.component.fileupload.NativeFileUploadDecoder.lambda$getUploadDirectory$3(NativeFileUploadDecoder.java:79)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.stream.Streams$StreamBuilderImpl.tryAdvance(Streams.java:397)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
at org.primefaces.component.fileupload.NativeFileUploadDecoder.getUploadDirectory(NativeFileUploadDecoder.java:82)
  1. Chunked FileUpload throws NPE if UPLOADER=comons and <init-param><param-name>uploadDirectory</param-name>...</init-param> is not configured in web.xml
java.lang.NullPointerException: Cannot invoke "java.io.File.getAbsolutePath()" because the return value of "org.primefaces.webapp.MultipartRequest.getUploadDirectory()" is null
	at org.primefaces.component.fileupload.CommonsFileUploadDecoder.getUploadDirectory(CommonsFileUploadDecoder.java:80)
	at org.primefaces.component.fileupload.CommonsFileUploadDecoder.getUploadDirectory(CommonsFileUploadDecoder.java:36)

Reproducer Former issue cannot be reproduced with primefaces-test project, since jetty adds some attributes to the request which hide the bug.

Reproducer for latter issue. PF-7617-chunked.zip

Environment:

  • PF Version: 10.0
  • JSF + version: ALL
  • Affected browsers: ALL

To Reproduce Steps to reproduce the behavior:

  1. Start server mvn jetty:run
  2. Go to ‘localhost:8080/primefaces-test/’
  3. Click ‘choose’
  4. Select any file bigger than 1MB
  5. Click ‘upload’
  6. See error in server log

Expected behavior RuntimeExceptions should not be thrown. Files should be uploaded without error.

Example XHTML

<h:form id="frmTest">
    <p:fileUpload id="fileupload" mode="advanced" maxChunkSize="65536" .../>
</h:form>

Example Bean see reproducer

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mellowarecommented, Jul 28, 2021

I assigned it to you. Thanks!

0reactions
wal-jancommented, Jul 28, 2021

primefaces-integration-test project utilizes TomEE. Looks like TomEE does not add request attributes (in contrary to Jetty). And the Reproducer does not set request attributes at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IIS7 refuses chunked-encoded file upload - Stack Overflow
I have a Windows/Apache2/PHP app that receives file using chunked encoding. The reason is that the file uploaded is dynamic and its length...
Read more >
Solved: Uploading file Via REST API and Triggering Imports
I am following this API Request: Upload a single chunk ... canRead()) { throw new RuntimeException("Input file must be a valid file. File...
Read more >
Java Stream - 2.8.x - Play Framework
Let's just use this streamed HttpEntity to specify the response body: ... For this kind of response we have to use Chunked transfer...
Read more >
Handling file uploads - Manual - PHP
throw new RuntimeException('Failed to move uploaded file. ... If you are going to do a file upload, I recommend you use the PHP...
Read more >
ojluni/src/main/java/java/net/HttpURLConnection.java
To upload data to a web server, configure the connection for output using ... throw new IllegalStateException ("Chunked encoding streaming mode set");.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found