Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9C97B200D33 for ; Wed, 8 Nov 2017 12:06:45 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 9B052160BE0; Wed, 8 Nov 2017 11:06:45 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B962B160BDA for ; Wed, 8 Nov 2017 12:06:44 +0100 (CET) Received: (qmail 70297 invoked by uid 500); 8 Nov 2017 11:06:43 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 70286 invoked by uid 99); 8 Nov 2017 11:06:43 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Nov 2017 11:06:43 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id A2AC33A028F for ; Wed, 8 Nov 2017 11:06:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1814567 - in /tomcat/trunk: java/org/apache/tomcat/util/buf/StringUtils.java test/org/apache/coyote/http11/TestAbstractHttp11Protocol.java test/org/apache/tomcat/util/buf/TestStringUtils.java webapps/docs/changelog.xml Date: Wed, 08 Nov 2017 11:06:39 -0000 To: dev@tomcat.apache.org From: markt@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20171108110641.A2AC33A028F@svn01-us-west.apache.org> archived-at: Wed, 08 Nov 2017 11:06:45 -0000 Author: markt Date: Wed Nov 8 11:06:39 2017 New Revision: 1814567 URL: http://svn.apache.org/viewvc?rev=1814567&view=rev Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=61668 Refactor StringUtils to better handle null inputs. Add test cases for bug and all StringUtils methods. Added: tomcat/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Protocol.java (with props) tomcat/trunk/test/org/apache/tomcat/util/buf/TestStringUtils.java (with props) Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/StringUtils.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/StringUtils.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/StringUtils.java?rev=1814567&r1=1814566&r2=1814567&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/StringUtils.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/StringUtils.java Wed Nov 8 11:06:39 2017 @@ -23,7 +23,8 @@ import java.util.function.Function; /** * Utility methods to build a separated list from a given set (not * java.util.Set) of inputs and return that list as a string or append it to an - * existing StringBuilder. + * existing StringBuilder. If the given set is null or empty, an empty string + * will be returned. */ public final class StringUtils { @@ -35,11 +36,17 @@ public final class StringUtils { public static String join(String[] array) { + if (array == null) { + return EMPTY_STRING; + } return join(Arrays.asList(array)); } public static void join(String[] array, char separator, StringBuilder sb) { + if (array == null) { + return; + } join(Arrays.asList(array), separator, sb); } @@ -51,7 +58,7 @@ public final class StringUtils { public static String join(Collection collection, char separator) { // Shortcut - if (collection.isEmpty()) { + if (collection == null || collection.isEmpty()) { return EMPTY_STRING; } @@ -68,12 +75,18 @@ public final class StringUtils { public static void join(T[] array, char separator, Function function, StringBuilder sb) { + if (array == null) { + return; + } join(Arrays.asList(array), separator, function, sb); } public static void join(Iterable iterable, char separator, Function function, StringBuilder sb) { + if (iterable == null) { + return; + } boolean first = true; for (T value : iterable) { if (first) { Added: tomcat/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Protocol.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Protocol.java?rev=1814567&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Protocol.java (added) +++ tomcat/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Protocol.java Wed Nov 8 11:06:39 2017 @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.coyote.http11; + +import org.junit.Test; + +public class TestAbstractHttp11Protocol { + + @Test + public void testGetSslProtocol() { + Http11Nio2Protocol protocol = new Http11Nio2Protocol(); + protocol.getSSLProtocol(); + } +} Propchange: tomcat/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Protocol.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/test/org/apache/tomcat/util/buf/TestStringUtils.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/buf/TestStringUtils.java?rev=1814567&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/util/buf/TestStringUtils.java (added) +++ tomcat/trunk/test/org/apache/tomcat/util/buf/TestStringUtils.java Wed Nov 8 11:06:39 2017 @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomcat.util.buf; + +import java.util.Collection; + +import org.junit.Assert; +import org.junit.Test; + +/* + * None of these tests should throw a NPE. + */ +public class TestStringUtils { + + @Test + public void testNullArray() { + Assert.assertEquals("", StringUtils.join((String[]) null)); + } + + + @Test + public void testNullArrayCharStringBuilder() { + StringBuilder sb = new StringBuilder(); + StringUtils.join((String[]) null, ',', sb); + Assert.assertEquals("", sb.toString()); + } + + + @Test + public void testNullCollection() { + Assert.assertEquals("", StringUtils.join((Collection) null)); + } + + + @Test + public void testNullCollectionChar() { + Assert.assertEquals("", StringUtils.join(null, ',')); + } + + + @Test + public void testNullIterableCharStringBuilder() { + StringBuilder sb = new StringBuilder(); + StringUtils.join((Iterable) null, ',', sb); + Assert.assertEquals("", sb.toString()); + } + + + @Test + public void testNullArrayCharFunctionStringBuilder() { + StringBuilder sb = new StringBuilder(); + StringUtils.join((String[]) null, ',', null, sb); + Assert.assertEquals("", sb.toString()); + } + + + @Test + public void testNullIterableCharFunctionStringBuilder() { + StringBuilder sb = new StringBuilder(); + StringUtils.join((Iterable) null, ',', null, sb); + Assert.assertEquals("", sb.toString()); + } +} Propchange: tomcat/trunk/test/org/apache/tomcat/util/buf/TestStringUtils.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1814567&r1=1814566&r2=1814567&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Wed Nov 8 11:06:39 2017 @@ -88,6 +88,10 @@ from 200 to 20. (remm) + 61668: Avoid a possible NPE when calling + AbstractHttp11Protocol.getSSLProtocol(). (markt) + + 61719: Avoid possible NPE calling InputStream.setReadListener with HTTP/2. (remm) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org