Skip to content

Incorrect use of ServletFileUpload (common-fileupload) results in NPE #37

@greglira

Description

@greglira

We implemented a lambda function (proxy to API Gateway method which consumes multipart content) using the aws-serverless-java-container library.
However, during the testing we found out that it didn't work: all requests were failing with java.lang.NullPointerException: No FileItemFactory has been set.
It seems like the no-args constructor was used in https://github.com/awslabs/aws-serverless-java-container/blob/master/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsProxyHttpServletRequest.java#L658
ServletFileUpload upload = new ServletFileUpload();
Javadoc of that constructior says:
Constructs an uninitialised instance of this class. A factory must be
configured, using setFileItemFactory(), before attempting
to parse requests.

However, we haven't found any setFileItemFactory() calls in the code.

So we changed line 658 to ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); and it worked fine.
Can you confirm if that is a problem/bug?
Also it would be great to add a test case for this code.

Thanks,
Greg

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions