Merge pull request #4479 from eclipse/jetty-9.4.x-4383-npe-multipart
Issue #4383 - Minimal NPE prevention on MultiPart
This commit is contained in:
commit
b75cf1c6a6
|
@ -60,10 +60,10 @@ public class MultiPartFormInputStream
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(MultiPartFormInputStream.class);
|
private static final Logger LOG = Log.getLogger(MultiPartFormInputStream.class);
|
||||||
private static final MultiMap<Part> EMPTY_MAP = new MultiMap<>(Collections.emptyMap());
|
private static final MultiMap<Part> EMPTY_MAP = new MultiMap<>(Collections.emptyMap());
|
||||||
|
private final MultiMap<Part> _parts;
|
||||||
private InputStream _in;
|
private InputStream _in;
|
||||||
private MultipartConfigElement _config;
|
private MultipartConfigElement _config;
|
||||||
private String _contentType;
|
private String _contentType;
|
||||||
private MultiMap<Part> _parts;
|
|
||||||
private Throwable _err;
|
private Throwable _err;
|
||||||
private File _tmpDir;
|
private File _tmpDir;
|
||||||
private File _contextTmpDir;
|
private File _contextTmpDir;
|
||||||
|
@ -341,16 +341,19 @@ public class MultiPartFormInputStream
|
||||||
if (_config == null)
|
if (_config == null)
|
||||||
_config = new MultipartConfigElement(_contextTmpDir.getAbsolutePath());
|
_config = new MultipartConfigElement(_contextTmpDir.getAbsolutePath());
|
||||||
|
|
||||||
|
MultiMap parts = new MultiMap();
|
||||||
|
|
||||||
if (in instanceof ServletInputStream)
|
if (in instanceof ServletInputStream)
|
||||||
{
|
{
|
||||||
if (((ServletInputStream)in).isFinished())
|
if (((ServletInputStream)in).isFinished())
|
||||||
{
|
{
|
||||||
_parts = EMPTY_MAP;
|
parts = EMPTY_MAP;
|
||||||
_parsed = true;
|
_parsed = true;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_in = new BufferedInputStream(in);
|
if (!_parsed)
|
||||||
|
_in = new BufferedInputStream(in);
|
||||||
|
_parts = parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -432,6 +435,9 @@ public class MultiPartFormInputStream
|
||||||
parse();
|
parse();
|
||||||
throwIfError();
|
throwIfError();
|
||||||
|
|
||||||
|
if (_parts.isEmpty())
|
||||||
|
return Collections.emptyList();
|
||||||
|
|
||||||
Collection<List<Part>> values = _parts.values();
|
Collection<List<Part>> values = _parts.values();
|
||||||
List<Part> parts = new ArrayList<>();
|
List<Part> parts = new ArrayList<>();
|
||||||
for (List<Part> o : values)
|
for (List<Part> o : values)
|
||||||
|
@ -492,9 +498,6 @@ public class MultiPartFormInputStream
|
||||||
Handler handler = new Handler();
|
Handler handler = new Handler();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// initialize
|
|
||||||
_parts = new MultiMap<>();
|
|
||||||
|
|
||||||
// if its not a multipart request, don't parse it
|
// if its not a multipart request, don't parse it
|
||||||
if (_contentType == null || !_contentType.startsWith("multipart/form-data"))
|
if (_contentType == null || !_contentType.startsWith("multipart/form-data"))
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -509,6 +509,16 @@ public class MultiPartFormInputStreamTest
|
||||||
assertThat(stuff.exists(), is(false)); //tmp file was removed after cleanup
|
assertThat(stuff.exists(), is(false)); //tmp file was removed after cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteNPE()
|
||||||
|
{
|
||||||
|
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(); // this should not be an NPE
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLFOnlyRequest()
|
public void testLFOnlyRequest()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
|
Loading…
Reference in New Issue