From 7c0266af4c15dec161b44212e78a4d1314f617f9 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 19 Aug 2019 10:08:21 +1000 Subject: [PATCH] this is not supposed to return null (#3998) see https://javaee.github.io/javaee-spec/javadocs/javax/servlet/http/Part.html#getHeaders-java.lang.String- this fix related tck test Signed-off-by: olivier lamy --- .../java/org/eclipse/jetty/http/MultiPartFormInputStream.java | 3 ++- .../org/eclipse/jetty/http/MultiPartFormInputStreamTest.java | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/MultiPartFormInputStream.java b/jetty-http/src/main/java/org/eclipse/jetty/http/MultiPartFormInputStream.java index 82e65604b7d..c135a18169a 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/MultiPartFormInputStream.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/MultiPartFormInputStream.java @@ -205,7 +205,8 @@ public class MultiPartFormInputStream @Override public Collection getHeaders(String name) { - return _headers.getValues(name); + Collection headers = _headers.getValues(name); + return headers == null ? Collections.emptyList():headers; } @Override diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartFormInputStreamTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartFormInputStreamTest.java index 9343f82e58a..9a940f6c50d 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartFormInputStreamTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartFormInputStreamTest.java @@ -786,6 +786,8 @@ public class MultiPartFormInputStreamTest assertThat(stuff.getContentType(), is("text/plain")); assertThat(stuff.getHeader("Content-Type"), is("text/plain")); assertThat(stuff.getHeaders("content-type").size(), is(1)); + assertNotNull(stuff.getHeaders("non existing part")); + assertThat(stuff.getHeaders("non existing part").size(), is(0)); assertThat(stuff.getHeader("content-disposition"), is("form-data; name=\"stuff\"; filename=\"" + filename + "\"")); assertThat(stuff.getHeaderNames().size(), is(2)); assertThat(stuff.getSize(), is(51L));