From b908c9eb0e010ed62d6fd1c7bd1ec4ca5bdc1853 Mon Sep 17 00:00:00 2001 From: Todd Lipcon Date: Tue, 5 Jul 2011 22:09:54 +0000 Subject: [PATCH] HADOOP-7440. HttpServer.getParameterValues throws NPE for missing parameters. Contributed by Uma Maheswara Rao G and Todd Lipcon. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1143212 13f79535-47bb-0310-9956-ffa450edef68 --- common/CHANGES.txt | 3 ++ .../org/apache/hadoop/http/HttpServer.java | 3 ++ .../apache/hadoop/http/TestHtmlQuoting.java | 31 +++++++++++++++++-- .../apache/hadoop/http/TestHttpServer.java | 26 ++++++++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/common/CHANGES.txt b/common/CHANGES.txt index b46dd5e9af..c84dc559c8 100644 --- a/common/CHANGES.txt +++ b/common/CHANGES.txt @@ -346,6 +346,9 @@ Trunk (unreleased changes) HADOOP-7090. Fix resource leaks in s3.INode, BloomMapFile, WritableUtils and CBZip2OutputStream. (Uma Maheswara Rao G via szetszwo) + HADOOP-7440. HttpServer.getParameterValues throws NPE for missing + parameters. (Uma Maheswara Rao G and todd via todd) + Release 0.22.0 - Unreleased INCOMPATIBLE CHANGES diff --git a/common/src/java/org/apache/hadoop/http/HttpServer.java b/common/src/java/org/apache/hadoop/http/HttpServer.java index 75b3bbac34..6d6864c63d 100644 --- a/common/src/java/org/apache/hadoop/http/HttpServer.java +++ b/common/src/java/org/apache/hadoop/http/HttpServer.java @@ -800,6 +800,9 @@ public String getParameter(String name) { public String[] getParameterValues(String name) { String unquoteName = HtmlQuoting.unquoteHtmlChars(name); String[] unquoteValue = rawRequest.getParameterValues(unquoteName); + if (unquoteValue == null) { + return null; + } String[] result = new String[unquoteValue.length]; for(int i=0; i < result.length; ++i) { result[i] = HtmlQuoting.quoteHtmlChars(unquoteValue[i]); diff --git a/common/src/test/core/org/apache/hadoop/http/TestHtmlQuoting.java b/common/src/test/core/org/apache/hadoop/http/TestHtmlQuoting.java index 1c3663a4fd..9fc53a3b6f 100644 --- a/common/src/test/core/org/apache/hadoop/http/TestHtmlQuoting.java +++ b/common/src/test/core/org/apache/hadoop/http/TestHtmlQuoting.java @@ -17,11 +17,12 @@ */ package org.apache.hadoop.http; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; + +import javax.servlet.http.HttpServletRequest; import org.junit.Test; +import org.mockito.Mockito; public class TestHtmlQuoting { @@ -62,4 +63,28 @@ private void runRoundTrip(String str) throws Exception { } runRoundTrip(buffer.toString()); } + + + @Test + public void testRequestQuoting() throws Exception { + HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class); + HttpServer.QuotingInputFilter.RequestQuoter quoter = + new HttpServer.QuotingInputFilter.RequestQuoter(mockReq); + + Mockito.doReturn("a