Skip to content

Commit

Permalink
Issue #4383 - Minimal NPE prevention on MultiPart
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Jan 15, 2020
1 parent 33a5a25 commit 37f8503
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Expand Up @@ -397,6 +397,13 @@ public Collection<Part> getParsedParts()
*/
public void deleteParts()
{
if (_parts == null)
{
// If we call deleteParts at this point, we are considered CLOSED
_err = new IllegalStateException("CLOSED via call to deleteParts()");
return;
}

MultiException err = null;
for (List<Part> parts : _parts.values())
{
Expand Down
Expand Up @@ -509,6 +509,20 @@ public void testPartTmpFileDeletion() throws Exception
assertThat(stuff.exists(), is(false)); //tmp file was removed after cleanup
}

@Test
public void testParseAfterCleanUp() throws Exception
{
final InputStream input = new ByteArrayInputStream(createMultipartRequestString("myFile").getBytes());
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 1024, 50);
MultiPartFormInputStream mpis = new MultiPartFormInputStream(input, _contentType, config, _tmpDir);

mpis.deleteParts();

// The call to getParts should throw because we have already cleaned up the parts.
Throwable error = assertThrows(IllegalStateException.class, mpis::getParts);
assertThat(error.getMessage(), containsString("CLOSED"));
}

@Test
public void testLFOnlyRequest()
throws Exception
Expand Down

0 comments on commit 37f8503

Please sign in to comment.