You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When iterating over the parts of a multipart request using the io.helidon.http.media.multipart.MultiPart iterator, calliing .hasNext() of .next() after the first call to .next() causes a NullPointerException to be thrown.
Environment Details
Helidon Version: 4.0.5
Helidon SE
JDK version: 21
OS: Linux x86
Docker version (if applicable): /
Problem Description
Current behavior: Iterating over parts of a multipart requests fails when calling .hasNext() or .next() on io.helidon.http.media.multipart.MultiPart after .next() was called once.
Expected behavior: Calling .hasNext() should return true as long as unread parts remain and a subsequent call to .next() should return the next io.helidon.http.media.multipart.ReadablePart instance from the request. If no more parts remain, .hasNext() should return false.
When I did this, the following stacktrace was printed:
io.helidon.http.RequestException: Cannot invoke "io.helidon.common.buffers.BufferData.available()" because "this.nextBuffer" is null
at io.helidon.http.RequestException$Builder.build(RequestException.java:139)
at io.helidon.webserver.http.ErrorHandlers.unhandledError(ErrorHandlers.java:202)
at io.helidon.webserver.http.ErrorHandlers.lambda$handleError$1(ErrorHandlers.java:182)
at java.base/java.util.Optional.ifPresentOrElse(Optional.java:198)
at io.helidon.webserver.http.ErrorHandlers.handleError(ErrorHandlers.java:181)
at io.helidon.webserver.http.ErrorHandlers.runWithErrorHandling(ErrorHandlers.java:118)
at io.helidon.webserver.http.Filters.filter(Filters.java:77)
at io.helidon.webserver.http.HttpRouting.route(HttpRouting.java:109)
at io.helidon.webserver.http1.Http1Connection.route(Http1Connection.java:396)
at io.helidon.webserver.http1.Http1Connection.handle(Http1Connection.java:169)
at io.helidon.webserver.ConnectionHandler.run(ConnectionHandler.java:155)
at io.helidon.common.task.InterruptableTask.call(InterruptableTask.java:47)
at io.helidon.webserver.ThreadPerTaskExecutor$ThreadBoundFuture.run(ThreadPerTaskExecutor.java:239)
at java.base/java.lang.VirtualThread.run(VirtualThread.java:311)
Caused by: java.lang.NullPointerException: Cannot invoke "io.helidon.common.buffers.BufferData.available()" because "this.nextBuffer" is null
at io.helidon.http.media.multipart.ReadablePartNoLength$PartInputStream.finish(ReadablePartNoLength.java:198)
at io.helidon.http.media.multipart.ReadablePartNoLength.finish(ReadablePartNoLength.java:77)
at io.helidon.http.media.multipart.MultiPartImpl.hasNext(MultiPartImpl.java:70)
at io.helidon.examples.media.multipart.FileService.upload(FileService.java:136)
at io.helidon.webserver.http.HttpRouting$RoutingExecutor.doRoute(HttpRouting.java:668)
at io.helidon.webserver.http.HttpRouting$RoutingExecutor.call(HttpRouting.java:627)
at io.helidon.webserver.http.HttpRouting$RoutingExecutor.call(HttpRouting.java:605)
at io.helidon.webserver.http.ErrorHandlers.runWithErrorHandling(ErrorHandlers.java:75)
... 8 more
Steps to reproduce
Create a new Project using this code snippet and run it
Send a POST multipart request with more than 2 parts, e.g. using:
curl --request POST 'http://localhost:8080' --form 'field_1=a' --form 'field_2=b'
The expected behavior of this procedure would be that the following output is printed:
field_1
field_2
The actual behavior is that only the first line including field_1 is printed, then the NullPointerException is thrown.
The text was updated successfully, but these errors were encountered:
brain-dev-null
changed the title
Calling .hasNext() or .next() on MultiPart Iterator after a one call to .next() causes NullPointerException
Calling .hasNext() or .next() on MultiPart Iterator after the first call to .next() causes NullPointerException
Feb 9, 2024
Reproduced - requires streaming (no Content-Length defined) multipart parts, which we did not test.
Added test to make sure both approaches work.
Fixed an additional problem, where calling consume would fail with an exception.
When iterating over the parts of a multipart request using the
io.helidon.http.media.multipart.MultiPart
iterator, calliing.hasNext()
of.next()
after the first call to.next()
causes aNullPointerException
to be thrown.Environment Details
Problem Description
Current behavior: Iterating over parts of a multipart requests fails when calling
.hasNext()
or.next()
onio.helidon.http.media.multipart.MultiPart
after.next()
was called once.Expected behavior: Calling
.hasNext()
should returntrue
as long as unread parts remain and a subsequent call to.next()
should return the nextio.helidon.http.media.multipart.ReadablePart
instance from the request. If no more parts remain,.hasNext()
should returnfalse
.Theis can be reproduced by running the Helidon SE MultiPart Example or the minimal example shown below.
When I did this, the following stacktrace was printed:
Steps to reproduce
The expected behavior of this procedure would be that the following output is printed:
The actual behavior is that only the first line including
field_1
is printed, then the NullPointerException is thrown.The text was updated successfully, but these errors were encountered: