hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1370923 [5/5] - in /httpcomponents/httpcore/trunk: httpcore-contrib/src/main/java/org/apache/http/contrib/compress/ httpcore-contrib/src/main/java/org/apache/http/contrib/logging/ httpcore-contrib/src/main/java/org/apache/http/contrib/sip/...
Date Wed, 08 Aug 2012 19:56:44 GMT
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestTargetHost.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestTargetHost.java?rev=1370923&r1=1370922&r2=1370923&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestTargetHost.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestTargetHost.java
Wed Aug  8 19:56:38 2012
@@ -37,9 +37,10 @@ import org.apache.http.HttpInetConnectio
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.HttpVersion;
-import org.apache.http.ProtocolVersion;
 import org.apache.http.ProtocolException;
+import org.apache.http.ProtocolVersion;
 import org.apache.http.annotation.Immutable;
+import org.apache.http.util.Args;
 
 /**
  * RequestTargetHost is responsible for adding <code>Host</code> header. This
@@ -56,12 +57,8 @@ public class RequestTargetHost implement
 
     public void process(final HttpRequest request, final HttpContext context)
             throws HttpException, IOException {
-        if (request == null) {
-            throw new IllegalArgumentException("HTTP request may not be null");
-        }
-        if (context == null) {
-            throw new IllegalArgumentException("HTTP context may not be null");
-        }
+        Args.notNull(request, "HTTP request");
+        Args.notNull(context, "HTTP context");
 
         ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
         String method = request.getRequestLine().getMethod();

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestUserAgent.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestUserAgent.java?rev=1370923&r1=1370922&r2=1370923&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestUserAgent.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/RequestUserAgent.java
Wed Aug  8 19:56:38 2012
@@ -34,6 +34,7 @@ import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.util.Args;
 
 /**
  * RequestUserAgent is responsible for adding <code>User-Agent</code> header.
@@ -56,9 +57,7 @@ public class RequestUserAgent implements
 
     public void process(final HttpRequest request, final HttpContext context)
         throws HttpException, IOException {
-        if (request == null) {
-            throw new IllegalArgumentException("HTTP request may not be null");
-        }
+        Args.notNull(request, "HTTP request");
         if (!request.containsHeader(HTTP.USER_AGENT)) {
             String useragent = HttpProtocolParams.getUserAgent(request.getParams());
             if (useragent != null) {

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java?rev=1370923&r1=1370922&r2=1370923&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseConnControl.java
Wed Aug  8 19:56:38 2012
@@ -39,6 +39,7 @@ import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.annotation.Immutable;
+import org.apache.http.util.Args;
 
 /**
  * ResponseConnControl is responsible for adding <code>Connection</code> header
@@ -57,12 +58,8 @@ public class ResponseConnControl impleme
 
     public void process(final HttpResponse response, final HttpContext context)
             throws HttpException, IOException {
-        if (response == null) {
-            throw new IllegalArgumentException("HTTP response may not be null");
-        }
-        if (context == null) {
-            throw new IllegalArgumentException("HTTP context may not be null");
-        }
+        Args.notNull(response, "HTTP response");
+        Args.notNull(context, "HTTP context");
         // Always drop connection after certain type of responses
         int status = response.getStatusLine().getStatusCode();
         if (status == HttpStatus.SC_BAD_REQUEST ||

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseContent.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseContent.java?rev=1370923&r1=1370922&r2=1370923&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseContent.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseContent.java
Wed Aug  8 19:56:38 2012
@@ -35,9 +35,10 @@ import org.apache.http.HttpResponse;
 import org.apache.http.HttpResponseInterceptor;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
-import org.apache.http.ProtocolVersion;
 import org.apache.http.ProtocolException;
+import org.apache.http.ProtocolVersion;
 import org.apache.http.annotation.Immutable;
+import org.apache.http.util.Args;
 
 /**
  * ResponseContent is the most important interceptor for outgoing responses.
@@ -88,9 +89,7 @@ public class ResponseContent implements 
      */
     public void process(final HttpResponse response, final HttpContext context)
             throws HttpException, IOException {
-        if (response == null) {
-            throw new IllegalArgumentException("HTTP response may not be null");
-        }
+        Args.notNull(response, "HTTP response");
         if (this.overwrite) {
             response.removeHeaders(HTTP.TRANSFER_ENCODING);
             response.removeHeaders(HTTP.CONTENT_LEN);

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseDate.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseDate.java?rev=1370923&r1=1370922&r2=1370923&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseDate.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseDate.java
Wed Aug  8 19:56:38 2012
@@ -34,6 +34,7 @@ import org.apache.http.HttpResponse;
 import org.apache.http.HttpResponseInterceptor;
 import org.apache.http.HttpStatus;
 import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.util.Args;
 
 /**
  * ResponseDate is responsible for adding <code>Date<c/ode> header to the
@@ -53,10 +54,7 @@ public class ResponseDate implements Htt
 
     public void process(final HttpResponse response, final HttpContext context)
             throws HttpException, IOException {
-        if (response == null) {
-            throw new IllegalArgumentException
-                ("HTTP response may not be null.");
-        }
+        Args.notNull(response, "HTTP response");
         int status = response.getStatusLine().getStatusCode();
         if ((status >= HttpStatus.SC_OK) &&
             !response.containsHeader(HTTP.DATE_HEADER)) {

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseServer.java?rev=1370923&r1=1370922&r2=1370923&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseServer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ResponseServer.java
Wed Aug  8 19:56:38 2012
@@ -34,6 +34,7 @@ import org.apache.http.HttpResponse;
 import org.apache.http.HttpResponseInterceptor;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.util.Args;
 
 /**
  * ResponseServer is responsible for adding <code>Server</code> header. This
@@ -56,9 +57,7 @@ public class ResponseServer implements H
 
     public void process(final HttpResponse response, final HttpContext context)
             throws HttpException, IOException {
-        if (response == null) {
-            throw new IllegalArgumentException("HTTP request may not be null");
-        }
+        Args.notNull(response, "HTTP response");
         if (!response.containsHeader(HTTP.SERVER_HEADER)) {
             String s = (String) response.getParams().getParameter(
                     CoreProtocolPNames.ORIGIN_SERVER);

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/UriPatternMatcher.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/UriPatternMatcher.java?rev=1370923&r1=1370922&r2=1370923&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/UriPatternMatcher.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/UriPatternMatcher.java
Wed Aug  8 19:56:38 2012
@@ -33,6 +33,7 @@ import java.util.Map;
 
 import org.apache.http.annotation.GuardedBy;
 import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.util.Args;
 
 /**
  * Maintains a map of objects keyed by a request URI pattern.
@@ -67,9 +68,7 @@ public class UriPatternMatcher<T> {
      * @param obj the object.
      */
     public synchronized void register(final String pattern, final T obj) {
-        if (pattern == null) {
-            throw new IllegalArgumentException("URI request pattern may not be null");
-        }
+        Args.notNull(pattern, "URI request pattern");
         this.map.put(pattern, obj);
     }
 
@@ -90,9 +89,7 @@ public class UriPatternMatcher<T> {
      */
     @Deprecated
     public synchronized void setHandlers(final Map<String, T> map) {
-        if (map == null) {
-            throw new IllegalArgumentException("Map of handlers may not be null");
-        }
+        Args.notNull(map, "Map of handlers");
         this.map.clear();
         this.map.putAll(map);
     }
@@ -102,9 +99,7 @@ public class UriPatternMatcher<T> {
      * @param map the map containing objects keyed by their URI patterns.
      */
     public synchronized void setObjects(final Map<String, T> map) {
-        if (map == null) {
-            throw new IllegalArgumentException("Map of handlers may not be null");
-        }
+        Args.notNull(map, "Map of handlers");
         this.map.clear();
         this.map.putAll(map);
     }
@@ -126,9 +121,7 @@ public class UriPatternMatcher<T> {
      * @return object or <code>null</code> if no match is found.
      */
     public synchronized T lookup(String requestURI) {
-        if (requestURI == null) {
-            throw new IllegalArgumentException("Request URI may not be null");
-        }
+        Args.notNull(requestURI, "Request URI");
         //Strip away the query part part if found
         int index = requestURI.indexOf("?");
         if (index != -1) {

Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Args.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Args.java?rev=1370923&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Args.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Args.java Wed
Aug  8 19:56:38 2012
@@ -0,0 +1,97 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.util;
+
+import java.util.Collection;
+
+public class Args {
+
+    public static void check(boolean expression, final String message) {
+        if (!expression) {
+            throw new IllegalArgumentException(message);
+        }
+    }
+    
+    public static <T> T notNull(final T argument, final String name) {
+        if (argument == null) {
+            throw new IllegalArgumentException(name + " may not be null");
+        }
+        return argument;
+    }
+    
+    public static <T extends CharSequence> T notEmpty(final T argument, final String
name) {
+        if (argument == null) {
+            throw new IllegalArgumentException(name + " may not be null");
+        }
+        for (int i = 0; i < argument.length(); i++) {
+            if (!Character.isWhitespace(argument.charAt(i))) {
+                return argument;
+            }
+        }
+        throw new IllegalArgumentException(name + " may not be empty");
+    }    
+    
+    public static <E, T extends Collection<E>> T notEmpty(final T argument, final
String name) {
+        if (argument == null) {
+            throw new IllegalArgumentException(name + " may not be null");
+        }
+        if (argument.isEmpty()) {
+            throw new IllegalArgumentException(name + " may not be empty");
+        }
+        return argument;
+    }
+
+    public static int positive(final int n, final String name) {
+        if (n <= 0) {
+            throw new IllegalArgumentException(name + " may not be negative or zero");
+        }
+        return n;
+    }
+    
+    public static long positive(final long n, final String name) {
+        if (n <= 0) {
+            throw new IllegalArgumentException(name + " may not be negative or zero");
+        }
+        return n;
+    }
+    
+    public static int notNegative(final int n, final String name) {
+        if (n < 0) {
+            throw new IllegalArgumentException(name + " may not be negative");
+        }
+        return n;
+    }
+    
+    public static long notNegative(final long n, final String name) {
+        if (n < 0) {
+            throw new IllegalArgumentException(name + " may not be negative");
+        }
+        return n;
+    }
+    
+}

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Args.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Args.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Args.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/ByteArrayBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/ByteArrayBuffer.java?rev=1370923&r1=1370922&r2=1370923&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/ByteArrayBuffer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/ByteArrayBuffer.java
Wed Aug  8 19:56:38 2012
@@ -52,9 +52,7 @@ public final class ByteArrayBuffer imple
      */
     public ByteArrayBuffer(int capacity) {
         super();
-        if (capacity < 0) {
-            throw new IllegalArgumentException("Buffer capacity may not be negative");
-        }
+        Args.notNegative(capacity, "Buffer capacity");
         this.buffer = new byte[capacity];
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/CharArrayBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/CharArrayBuffer.java?rev=1370923&r1=1370922&r2=1370923&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/CharArrayBuffer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/CharArrayBuffer.java
Wed Aug  8 19:56:38 2012
@@ -53,9 +53,7 @@ public final class CharArrayBuffer imple
      */
     public CharArrayBuffer(int capacity) {
         super();
-        if (capacity < 0) {
-            throw new IllegalArgumentException("Buffer capacity may not be negative");
-        }
+        Args.notNegative(capacity, "Buffer capacity");
         this.buffer = new char[capacity];
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EncodingUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EncodingUtils.java?rev=1370923&r1=1370922&r2=1370923&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EncodingUtils.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EncodingUtils.java
Wed Aug  8 19:56:38 2012
@@ -53,17 +53,9 @@ public final class EncodingUtils {
         final byte[] data,
         int offset,
         int length,
-        String charset
-    ) {
-
-        if (data == null) {
-            throw new IllegalArgumentException("Parameter may not be null");
-        }
-
-        if (charset == null || charset.length() == 0) {
-            throw new IllegalArgumentException("charset may not be null or empty");
-        }
-
+        String charset) {
+        Args.notNull(data, "Input");
+        Args.notEmpty(charset, "Charset");
         try {
             return new String(data, offset, length, charset);
         } catch (UnsupportedEncodingException e) {
@@ -82,9 +74,7 @@ public final class EncodingUtils {
      * @return The result of the conversion.
      */
     public static String getString(final byte[] data, final String charset) {
-        if (data == null) {
-            throw new IllegalArgumentException("Parameter may not be null");
-        }
+        Args.notNull(data, "Input");
         return getString(data, 0, data.length, charset);
     }
 
@@ -97,15 +87,8 @@ public final class EncodingUtils {
      * @return The resulting byte array.
      */
     public static byte[] getBytes(final String data, final String charset) {
-
-        if (data == null) {
-            throw new IllegalArgumentException("data may not be null");
-        }
-
-        if (charset == null || charset.length() == 0) {
-            throw new IllegalArgumentException("charset may not be null or empty");
-        }
-
+        Args.notNull(data, "Input");
+        Args.notEmpty(charset, "Charset");
         try {
             return data.getBytes(charset);
         } catch (UnsupportedEncodingException e) {
@@ -120,11 +103,7 @@ public final class EncodingUtils {
      * @return The string as a byte array.
      */
     public static byte[] getAsciiBytes(final String data) {
-
-        if (data == null) {
-            throw new IllegalArgumentException("Parameter may not be null");
-        }
-
+        Args.notNull(data, "Input");
         try {
             return data.getBytes(Consts.ASCII.name());
         } catch (UnsupportedEncodingException e) {
@@ -143,11 +122,7 @@ public final class EncodingUtils {
      * @return The string representation of the byte array
      */
     public static String getAsciiString(final byte[] data, int offset, int length) {
-
-        if (data == null) {
-            throw new IllegalArgumentException("Parameter may not be null");
-        }
-
+        Args.notNull(data, "Input");
         try {
             return new String(data, offset, length, Consts.ASCII.name());
         } catch (UnsupportedEncodingException e) {
@@ -164,9 +139,7 @@ public final class EncodingUtils {
      * @return The string representation of the byte array
      */
     public static String getAsciiString(final byte[] data) {
-        if (data == null) {
-            throw new IllegalArgumentException("Parameter may not be null");
-        }
+        Args.notNull(data, "Input");
         return getAsciiString(data, 0, data.length);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EntityUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EntityUtils.java?rev=1370923&r1=1370922&r2=1370923&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EntityUtils.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/EntityUtils.java
Wed Aug  8 19:56:38 2012
@@ -101,9 +101,7 @@ public final class EntityUtils {
      */
     public static void updateEntity(
             final HttpResponse response, final HttpEntity entity) throws IOException {
-        if(response == null) {
-            throw new IllegalArgumentException("Response cannot be null");
-        }
+        Args.notNull(response, "Response");
         consume(response.getEntity());
         response.setEntity(entity);
     }
@@ -118,17 +116,14 @@ public final class EntityUtils {
      * @throws IllegalArgumentException if entity is null or if content length > Integer.MAX_VALUE
      */
     public static byte[] toByteArray(final HttpEntity entity) throws IOException {
-        if (entity == null) {
-            throw new IllegalArgumentException("HTTP entity may not be null");
-        }
+        Args.notNull(entity, "Entity");
         InputStream instream = entity.getContent();
         if (instream == null) {
             return null;
         }
         try {
-            if (entity.getContentLength() > Integer.MAX_VALUE) {
-                throw new IllegalArgumentException("HTTP entity too large to be buffered
in memory");
-            }
+            Args.check(entity.getContentLength() <= Integer.MAX_VALUE, 
+                    "HTTP entity too large to be buffered in memory");
             int i = (int)entity.getContentLength();
             if (i < 0) {
                 i = 4096;
@@ -157,9 +152,7 @@ public final class EntityUtils {
      */
     @Deprecated
     public static String getContentCharSet(final HttpEntity entity) throws ParseException
{
-        if (entity == null) {
-            throw new IllegalArgumentException("HTTP entity may not be null");
-        }
+        Args.notNull(entity, "Entity");
         String charset = null;
         if (entity.getContentType() != null) {
             HeaderElement values[] = entity.getContentType().getElements();
@@ -187,9 +180,7 @@ public final class EntityUtils {
      */
     @Deprecated
     public static String getContentMimeType(final HttpEntity entity) throws ParseException
{
-        if (entity == null) {
-            throw new IllegalArgumentException("HTTP entity may not be null");
-        }
+        Args.notNull(entity, "Entity");
         String mimeType = null;
         if (entity.getContentType() != null) {
             HeaderElement values[] = entity.getContentType().getElements();
@@ -215,17 +206,14 @@ public final class EntityUtils {
      */
     public static String toString(
             final HttpEntity entity, final Charset defaultCharset) throws IOException, ParseException
{
-        if (entity == null) {
-            throw new IllegalArgumentException("HTTP entity may not be null");
-        }
+        Args.notNull(entity, "Entity");
         InputStream instream = entity.getContent();
         if (instream == null) {
             return null;
         }
         try {
-            if (entity.getContentLength() > Integer.MAX_VALUE) {
-                throw new IllegalArgumentException("HTTP entity too large to be buffered
in memory");
-            }
+            Args.check(entity.getContentLength() <= Integer.MAX_VALUE, 
+                    "HTTP entity too large to be buffered in memory");
             int i = (int)entity.getContentLength();
             if (i < 0) {
                 i = 4096;

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/VersionInfo.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/VersionInfo.java?rev=1370923&r1=1370922&r2=1370923&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/VersionInfo.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/VersionInfo.java
Wed Aug  8 19:56:38 2012
@@ -29,10 +29,10 @@ package org.apache.http.util;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import java.util.ArrayList;
 
 
 /**
@@ -88,11 +88,7 @@ public class VersionInfo {
      */
     protected VersionInfo(String pckg, String module,
                           String release, String time, String clsldr) {
-        if (pckg == null) {
-            throw new IllegalArgumentException
-                ("Package identifier must not be null.");
-        }
-
+        Args.notNull(pckg, "Package identifier");
         infoPackage     = pckg;
         infoModule      = (module  != null) ? module  : UNAVAILABLE;
         infoRelease     = (release != null) ? release : UNAVAILABLE;
@@ -197,11 +193,7 @@ public class VersionInfo {
      */
     public final static VersionInfo[] loadVersionInfo(String[] pckgs,
                                                       ClassLoader clsldr) {
-        if (pckgs == null) {
-            throw new IllegalArgumentException
-                ("Package identifier list must not be null.");
-        }
-
+        Args.notNull(pckgs, "Package identifier array");
         List<VersionInfo> vil = new ArrayList<VersionInfo>(pckgs.length);
         for (int i=0; i<pckgs.length; i++) {
             VersionInfo vi = loadVersionInfo(pckgs[i], clsldr);
@@ -227,11 +219,7 @@ public class VersionInfo {
      */
     public final static VersionInfo loadVersionInfo(final String pckg,
                                                     ClassLoader clsldr) {
-        if (pckg == null) {
-            throw new IllegalArgumentException
-                ("Package identifier must not be null.");
-        }
-
+        Args.notNull(pckg, "Package identifier");
         if (clsldr == null)
             clsldr = Thread.currentThread().getContextClassLoader();
 
@@ -274,11 +262,7 @@ public class VersionInfo {
      */
     protected final static VersionInfo fromMap(String pckg, Map<?, ?> info,
                                                ClassLoader clsldr) {
-        if (pckg == null) {
-            throw new IllegalArgumentException
-                ("Package identifier must not be null.");
-        }
-
+        Args.notNull(pckg, "Package identifier");
         String module = null;
         String release = null;
         String timestamp = null;

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestNoConnectionReuseStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestNoConnectionReuseStrategy.java?rev=1370923&r1=1370922&r2=1370923&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestNoConnectionReuseStrategy.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestNoConnectionReuseStrategy.java
Wed Aug  8 19:56:38 2012
@@ -47,16 +47,6 @@ public class TestNoConnectionReuseStrate
         MockitoAnnotations.initMocks(this);
     }
 
-    @Test(expected=IllegalArgumentException.class)
-    public void testNullResponse() throws Exception {
-        strat.keepAlive(null, context);
-    }
-
-    @Test(expected=IllegalArgumentException.class)
-    public void testNullContext() throws Exception {
-        strat.keepAlive(response, null);
-    }
-
     @Test
     public void testGoodcall() throws Exception {
         Assert.assertFalse(strat.keepAlive(response, context));

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/integration/TestSyncHttp.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/integration/TestSyncHttp.java?rev=1370923&r1=1370922&r2=1370923&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/integration/TestSyncHttp.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/integration/TestSyncHttp.java
Wed Aug  8 19:56:38 2012
@@ -618,12 +618,6 @@ public class TestSyncHttp {
 
         public RepeatingEntity(final String content, Charset charset, int n) {
             super();
-            if (content == null) {
-                throw new IllegalArgumentException("Content may not be null");
-            }
-            if (n <= 0) {
-                throw new IllegalArgumentException("N may not be negative or zero");
-            }
             if (charset == null) {
                 charset = Charset.forName("US-ASCII"); // US-ASCII is built-in
             }



Mime
View raw message