From 52ddef91faef5529bbb4d3d358dfbf5f2a10c56e Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Thu, 6 Jun 2013 14:31:08 +0000 Subject: [PATCH] [HTTPCLIENT-1365] NPE when ManagedHttpClientConnectionFactory.create(ConnectionConfig) is called with null. Contributed by Gary Gregory git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1490299 13f79535-47bb-0310-9956-ffa450edef68 --- RELEASE_NOTES.txt | 3 ++ .../ManagedHttpClientConnectionFactory.java | 4 +- ...estManagedHttpClientConnectionFactory.java | 52 +++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 httpclient/src/test/java/org/apache/http/impl/conn/TestManagedHttpClientConnectionFactory.java diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 0a199b2d1..6a10ed5c6 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,6 +1,9 @@ Changes since release 4.3 BETA2 ------------------- +* [HTTPCLIENT-1365] NPE when ManagedHttpClientConnectionFactory.create(ConnectionConfig) is called with null. + Contributed by Gary Gregory + * [HTTPCLIENT-1362] Better error messages for connect timed out and connection refused exceptions. Contributed by Oleg Kalnichevski diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionFactory.java b/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionFactory.java index bb4c0ce67..332449fbb 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionFactory.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/ManagedHttpClientConnectionFactory.java @@ -104,8 +104,8 @@ public class ManagedHttpClientConnectionFactory implements HttpConnectionFactory log, headerlog, wirelog, - config.getBufferSize(), - config.getFragmentSizeHint(), + cconfig.getBufferSize(), + cconfig.getFragmentSizeHint(), chardecoder, charencoder, cconfig.getMessageConstraints(), diff --git a/httpclient/src/test/java/org/apache/http/impl/conn/TestManagedHttpClientConnectionFactory.java b/httpclient/src/test/java/org/apache/http/impl/conn/TestManagedHttpClientConnectionFactory.java new file mode 100644 index 000000000..f09c5bbe9 --- /dev/null +++ b/httpclient/src/test/java/org/apache/http/impl/conn/TestManagedHttpClientConnectionFactory.java @@ -0,0 +1,52 @@ +/* + * ==================================================================== + * 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. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ +package org.apache.http.impl.conn; + +import junit.framework.Assert; + +import org.apache.http.config.ConnectionConfig; +import org.apache.http.conn.ManagedHttpClientConnection; +import org.junit.Test; + +public class TestManagedHttpClientConnectionFactory { + + @Test + public void testDefaultConnectionConfig() throws Exception { + validateDefault(ManagedHttpClientConnectionFactory.INSTANCE.create(ConnectionConfig.DEFAULT)); + } + + private void validateDefault(ManagedHttpClientConnection managedHttpClientConnection) { + // Nothing really interesting to check here + Assert.assertNotNull(managedHttpClientConnection.getId()); + } + + @Test + public void testNullConnectionConfig() throws Exception { + // Should not NPE + validateDefault(ManagedHttpClientConnectionFactory.INSTANCE.create(null)); + } +}