Skip to content

Commit

Permalink
Issue #4383 - avoid NPE from MultiPart Cleanup
Browse files Browse the repository at this point in the history
Always assign _parts when constructed so it is never null.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Dec 3, 2019
1 parent d7cf372 commit 269e885
Showing 1 changed file with 3 additions and 8 deletions.
Expand Up @@ -59,11 +59,10 @@
public class MultiPartFormInputStream
{
private static final Logger LOG = Log.getLogger(MultiPartFormInputStream.class);
private static final MultiMap<Part> EMPTY_MAP = new MultiMap<>(Collections.emptyMap());
private InputStream _in;
private MultipartConfigElement _config;
private String _contentType;
private MultiMap<Part> _parts;
private MultiMap<Part> _parts = new MultiMap<>();

This comment has been minimized.

Copy link
@behrangsa

behrangsa Dec 3, 2019

I might be 100% wrong, but it might be a good idea to declare all these variables as volatile (or final which wouldn't need volatile), if the variables might get set in one thread and read in another thread.

private Throwable _err;
private File _tmpDir;
private File _contextTmpDir;
Expand Down Expand Up @@ -345,7 +344,6 @@ public MultiPartFormInputStream(InputStream in, String contentType, MultipartCon
{
if (((ServletInputStream)in).isFinished())
{
_parts = EMPTY_MAP;
_parsed = true;
return;
}
Expand All @@ -358,7 +356,7 @@ public MultiPartFormInputStream(InputStream in, String contentType, MultipartCon
*/
public boolean isEmpty()
{
if (_parts == null)
if (_parts.isEmpty())
return true;

Collection<List<Part>> values = _parts.values();
Expand All @@ -379,7 +377,7 @@ public boolean isEmpty()
@Deprecated
public Collection<Part> getParsedParts()
{
if (_parts == null)
if (_parts.isEmpty())
return Collections.emptyList();

Collection<List<Part>> values = _parts.values();
Expand Down Expand Up @@ -492,9 +490,6 @@ protected void parse()
Handler handler = new Handler();
try
{
// initialize
_parts = new MultiMap<>();

// if its not a multipart request, don't parse it
if (_contentType == null || !_contentType.startsWith("multipart/form-data"))
return;
Expand Down

0 comments on commit 269e885

Please sign in to comment.