hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1423508 - in /httpcomponents/httpcore/trunk: httpcore-ab/src/test/java/org/apache/http/benchmark/ httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ httpcore-nio/src/mai...
Date Tue, 18 Dec 2012 16:12:21 GMT
Author: olegk
Date: Tue Dec 18 16:12:13 2012
New Revision: 1423508

URL: http://svn.apache.org/viewvc?rev=1423508&view=rev
Log:
Use Asserts to verify object state

Modified:
    httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/HttpServer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractContentEncoder.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIODispatch.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/RequestExecutionHandler.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestThrottlingNHttpHandlers.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/ContentEncoderMock.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/ProtocolVersion.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BasicHttpEntity.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicListHeaderIterator.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Args.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Asserts.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/HttpServer.java

Modified: httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/HttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/HttpServer.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/HttpServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/HttpServer.java Tue Dec 18 16:12:13 2012
@@ -51,6 +51,7 @@ import org.apache.http.protocol.Response
 import org.apache.http.protocol.ResponseDate;
 import org.apache.http.protocol.ResponseServer;
 import org.apache.http.protocol.UriHttpRequestHandlerMapper;
+import org.apache.http.util.Asserts;
 
 public class HttpServer {
 
@@ -96,9 +97,7 @@ public class HttpServer {
     }
 
     public void start() {
-        if (this.listener != null) {
-            throw new IllegalStateException("Listener already running");
-        }
+        Asserts.check(this.listener == null, "Listener already running");
         this.listener = new Thread(new Runnable() {
 
             public void run() {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractContentEncoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractContentEncoder.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractContentEncoder.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractContentEncoder.java Tue Dec 18 16:12:13 2012
@@ -35,6 +35,7 @@ import org.apache.http.impl.io.HttpTrans
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.reactor.SessionOutputBuffer;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 /**
  * Abstract {@link ContentEncoder} that serves as a base for all content
@@ -81,9 +82,7 @@ public abstract class AbstractContentEnc
     }
 
     protected void assertNotCompleted() {
-        if (this.completed) {
-            throw new IllegalStateException("Encoding process already completed");
-        }
+        Asserts.check(!this.completed, "Encoding process already completed");
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIODispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIODispatch.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIODispatch.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIODispatch.java Tue Dec 18 16:12:13 2012
@@ -33,6 +33,7 @@ import org.apache.http.annotation.Immuta
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.reactor.ssl.SSLIOSession;
+import org.apache.http.util.Asserts;
 
 /**
  * Abstract {@link IOEventDispatch} implementation that supports both plain (non-encrypted)
@@ -59,9 +60,7 @@ public abstract class AbstractIODispatch
     protected abstract void onTimeout(T conn);
 
     private void ensureNotNull(final T conn) {
-        if (conn == null) {
-            throw new IllegalStateException("HTTP connection is null");
-        }
+        Asserts.notNull(conn, "HTTP connection");
     }
 
     public void connected(final IOSession session) {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractIOReactor.java Tue Dec 18 16:12:13 2012
@@ -47,6 +47,7 @@ import org.apache.http.nio.reactor.IORea
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 /**
  * Generic implementation of {@link IOReactor} that can used as a subclass
@@ -458,9 +459,7 @@ public abstract class AbstractIOReactor 
 
     private boolean queueInterestOps(final InterestOpEntry entry) {
         // validity checks
-        if (!this.interestOpsQueueing) {
-            throw new IllegalStateException("Interest ops queueing not enabled");
-        }
+        Asserts.check(this.interestOpsQueueing, "Interest ops queueing not enabled");
         if (entry == null) {
             return false;
         }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/AbstractMultiworkerIOReactor.java Tue Dec 18 16:12:13 2012
@@ -52,6 +52,7 @@ import org.apache.http.params.BasicHttpP
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 /**
  * Generic implementation of {@link IOReactor} that can run multiple
@@ -312,9 +313,8 @@ public abstract class AbstractMultiworke
                 this.statusLock.notifyAll();
                 return;
             }
-            if (this.status.compareTo(IOReactorStatus.INACTIVE) != 0) {
-                throw new IllegalStateException("Illegal state: " + this.status);
-            }
+            Asserts.check(this.status.compareTo(IOReactorStatus.INACTIVE) == 0,
+                    "Illegal state %s", this.status);
             this.status = IOReactorStatus.ACTIVE;
             // Start I/O dispatchers
             for (int i = 0; i < this.dispatchers.length; i++) {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java Tue Dec 18 16:12:13 2012
@@ -47,6 +47,7 @@ import org.apache.http.nio.reactor.IORea
 import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.nio.reactor.SessionRequestCallback;
 import org.apache.http.params.HttpParams;
+import org.apache.http.util.Asserts;
 
 /**
  * Default implementation of {@link ConnectingIOReactor}. This class extends
@@ -222,10 +223,8 @@ public class DefaultConnectingIOReactor 
             final SocketAddress localAddress,
             final Object attachment,
             final SessionRequestCallback callback) {
-
-        if (this.status.compareTo(IOReactorStatus.ACTIVE) > 0) {
-            throw new IllegalStateException("I/O reactor has been shut down");
-        }
+        Asserts.check(this.status.compareTo(IOReactorStatus.ACTIVE) <= 0,
+            "I/O reactor has been shut down");
         SessionRequestImpl sessionRequest = new SessionRequestImpl(
                 remoteAddress, localAddress, attachment, callback);
         sessionRequest.setConnectTimeout(this.config.getConnectTimeout());

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultListeningIOReactor.java Tue Dec 18 16:12:13 2012
@@ -47,6 +47,7 @@ import org.apache.http.nio.reactor.IORea
 import org.apache.http.nio.reactor.ListenerEndpoint;
 import org.apache.http.nio.reactor.ListeningIOReactor;
 import org.apache.http.params.HttpParams;
+import org.apache.http.util.Asserts;
 
 /**
  * Default implementation of {@link ListeningIOReactor}. This class extends
@@ -209,9 +210,8 @@ public class DefaultListeningIOReactor e
     }
 
     public ListenerEndpoint listen(final SocketAddress address) {
-        if (this.status.compareTo(IOReactorStatus.ACTIVE) > 0) {
-            throw new IllegalStateException("I/O reactor has been shut down");
-        }
+        Asserts.check(this.status.compareTo(IOReactorStatus.ACTIVE) <= 0,
+                "I/O reactor has been shut down");
         ListenerEndpointImpl request = createEndpoint(address);
         this.requestQueue.add(request);
         this.selector.wakeup();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java Tue Dec 18 16:12:13 2012
@@ -41,6 +41,7 @@ import org.apache.http.nio.protocol.Basi
 import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.nio.util.SimpleInputBuffer;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 /**
  * A {@link ConsumingNHttpEntity} that consumes content into a buffer. The
@@ -95,12 +96,8 @@ public class BufferingNHttpEntity extend
      */
     @Override
     public InputStream getContent() throws IOException {
-        if (!this.finished) {
-            throw new IllegalStateException("Entity content has not been fully received");
-        }
-        if (this.consumed) {
-            throw new IllegalStateException("Entity content has been consumed");
-        }
+        Asserts.check(this.finished, "Entity content has not been fully received");
+        Asserts.check(!this.consumed, "Entity content has been consumed");
         this.consumed = true;
         return new ContentInputStream(this.buffer);
     }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java Tue Dec 18 16:12:13 2012
@@ -53,6 +53,7 @@ import org.apache.http.pool.ConnPoolCont
 import org.apache.http.pool.PoolEntry;
 import org.apache.http.pool.PoolStats;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 /**
  * Abstract non-blocking connection pool.
@@ -168,9 +169,7 @@ public abstract class AbstractNIOConnPoo
             final FutureCallback<E> callback) {
         Args.notNull(route, "Route");
         Args.notNull(tunit, "Time unit");
-        if (this.isShutDown) {
-            throw new IllegalStateException("Session pool has been shut down");
-        }
+        Asserts.check(!this.isShutDown, "Connection pool shut down");
         this.lock.lock();
         try {
             long timeout = connectTimeout > 0 ? tunit.toMillis(connectTimeout) : 0;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/pool/RouteSpecificPool.java Tue Dec 18 16:12:13 2012
@@ -39,6 +39,7 @@ import org.apache.http.concurrent.BasicF
 import org.apache.http.nio.reactor.SessionRequest;
 import org.apache.http.pool.PoolEntry;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 @NotThreadSafe
 abstract class RouteSpecificPool<T, C, E extends PoolEntry<T, C>> {
@@ -121,10 +122,7 @@ abstract class RouteSpecificPool<T, C, E
     public void free(final E entry, boolean reusable) {
         Args.notNull(entry, "Pool entry");
         boolean found = this.leased.remove(entry);
-        if (!found) {
-            throw new IllegalStateException("Entry " + entry +
-                    " has not been leased from this pool");
-        }
+        Asserts.check(found, "Entry %s has not been leased from this pool", entry);
         if (reusable) {
             this.available.addFirst(entry);
         }
@@ -138,9 +136,7 @@ abstract class RouteSpecificPool<T, C, E
 
     private BasicFuture<E> removeRequest(final SessionRequest request) {
         BasicFuture<E> future = this.pending.remove(request);
-        if (future == null) {
-            throw new IllegalStateException("Invalid session request");
-        }
+        Asserts.notNull(future, "Session request future");
         return future;
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java Tue Dec 18 16:12:13 2012
@@ -61,6 +61,7 @@ import org.apache.http.protocol.HttpCont
 import org.apache.http.protocol.HttpExpectationVerifier;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 import org.apache.http.util.EncodingUtils;
 
 /**
@@ -658,27 +659,21 @@ public class AsyncNHttpServiceHandler ex
 
         public void submitResponse(final HttpResponse response) {
             Args.notNull(response, "Response");
-            if (this.triggered) {
-                throw new IllegalStateException("Response already triggered");
-            }
+            Asserts.check(!this.triggered, "Response already triggered");
             this.triggered = true;
             this.connState.setResponse(response);
             this.iocontrol.requestOutput();
         }
 
         public void handleException(final HttpException ex) {
-            if (this.triggered) {
-                throw new IllegalStateException("Response already triggered");
-            }
+            Asserts.check(!this.triggered, "Response already triggered");
             this.triggered = true;
             this.connState.setHttpException(ex);
             this.iocontrol.requestOutput();
         }
 
         public void handleException(final IOException ex) {
-            if (this.triggered) {
-                throw new IllegalStateException("Response already triggered");
-            }
+            Asserts.check(!this.triggered, "Response already triggered");
             this.triggered = true;
             this.connState.setIOException(ex);
             this.iocontrol.requestOutput();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java Tue Dec 18 16:12:13 2012
@@ -40,6 +40,7 @@ import org.apache.http.nio.entity.Conten
 import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.nio.util.SimpleInputBuffer;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Asserts;
 
 /**
  * Basic implementation of {@link HttpAsyncRequestConsumer}. Please note that
@@ -81,9 +82,7 @@ public class BasicAsyncRequestConsumer e
     @Override
     protected void onContentReceived(
             final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
-        if (this.buf == null) {
-            throw new IllegalStateException("Content buffer is null");
-        }
+        Asserts.notNull(this.buf, "Content buffer");
         this.buf.consumeContent(decoder);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java Tue Dec 18 16:12:13 2012
@@ -39,6 +39,7 @@ import org.apache.http.nio.entity.Conten
 import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.nio.util.SimpleInputBuffer;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Asserts;
 
 /**
  * Basic implementation of {@link HttpAsyncResponseConsumer}. Please note that
@@ -79,9 +80,7 @@ public class BasicAsyncResponseConsumer 
     @Override
     protected void onContentReceived(
             final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
-        if (this.buf == null) {
-            throw new IllegalStateException("Content buffer is null");
-        }
+        Asserts.notNull(this.buf, "Content buffer");
         this.buf.consumeContent(decoder);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java Tue Dec 18 16:12:13 2012
@@ -50,6 +50,7 @@ import org.apache.http.protocol.Executio
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 /**
  * <tt>HttpAsyncRequestExecutor</tt> is a fully asynchronous HTTP client side
@@ -306,9 +307,7 @@ public class HttpAsyncRequestExecutor im
     }
 
     private State ensureNotNull(final State state) {
-        if (state == null) {
-            throw new IllegalStateException("HTTP exchange state is null");
-        }
+        Asserts.notNull(state, "HTTP exchange state");
         return state;
     }
 
@@ -317,9 +316,7 @@ public class HttpAsyncRequestExecutor im
     }
 
     private HttpAsyncRequestExecutionHandler<?> ensureNotNull(final HttpAsyncRequestExecutionHandler<?> handler) {
-        if (handler == null) {
-            throw new IllegalStateException("HTTP exchange handler is null");
-        }
+        Asserts.notNull(handler, "HTTP exchange handler");
         return handler;
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncService.java Tue Dec 18 16:12:13 2012
@@ -61,6 +61,7 @@ import org.apache.http.protocol.Executio
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 /**
  * <tt>HttpAsyncService</tt> is a fully asynchronous HTTP server side protocol
@@ -414,16 +415,12 @@ public class HttpAsyncService implements
     }
 
     private State ensureNotNull(final State state) {
-        if (state == null) {
-            throw new IllegalStateException("HTTP exchange state is null");
-        }
+        Asserts.notNull(state, "HTTP exchange state");
         return state;
     }
 
     private HttpAsyncRequestConsumer<Object> ensureNotNull(final HttpAsyncRequestConsumer<Object> requestConsumer) {
-        if (requestConsumer == null) {
-            throw new IllegalStateException("Request consumer is null");
-        }
+        Asserts.notNull(requestConsumer, "Request consumer");
         return requestConsumer;
     }
 
@@ -765,9 +762,7 @@ public class HttpAsyncService implements
 
         public void setCallback(final Cancellable cancellable) {
             synchronized (this) {
-                if (this.completed) {
-                    throw new IllegalStateException("Response already submitted");
-                }
+                Asserts.check(!this.completed, "Response already submitted");
                 if (this.state.isTerminated() && cancellable != null) {
                     cancellable.cancel();
                 } else {
@@ -780,9 +775,7 @@ public class HttpAsyncService implements
         public void submitResponse(final HttpAsyncResponseProducer responseProducer) {
             Args.notNull(responseProducer, "Response producer");
             synchronized (this) {
-                if (this.completed) {
-                    throw new IllegalStateException("Response already submitted");
-                }
+                Asserts.check(!this.completed, "Response already submitted");
                 this.completed = true;
                 if (!this.state.isTerminated()) {
                     this.state.setResponseProducer(responseProducer);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java Tue Dec 18 16:12:13 2012
@@ -49,6 +49,7 @@ import org.apache.http.nio.reactor.IOSes
 import org.apache.http.nio.reactor.SessionBufferStatus;
 import org.apache.http.nio.reactor.SocketAccessor;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 /**
  * <tt>SSLIOSession</tt> is a decorator class intended to transparently extend
@@ -161,9 +162,7 @@ public class SSLIOSession implements IOS
      * @throws IllegalStateException if the session has already been initialized.
      */
     public synchronized void initialize(final SSLMode mode) throws SSLException {
-        if (this.initialized) {
-            throw new IllegalStateException("SSL I/O session already initialized");
-        }
+        Asserts.check(!this.initialized, "SSL I/O session already initialized");
         if (this.status >= IOSession.CLOSING) {
             return;
         }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/util/SharedOutputBuffer.java Tue Dec 18 16:12:13 2012
@@ -35,6 +35,7 @@ import org.apache.http.annotation.Thread
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 /**
  * Implementation of the {@link ContentOutputBuffer} interface that can be
@@ -214,9 +215,7 @@ public class SharedOutputBuffer extends 
         }
         this.lock.lock();
         try {
-            if (this.shutdown || this.endOfStream) {
-                throw new IllegalStateException("Buffer already closed for writing");
-            }
+            Asserts.check(!this.shutdown && !this.endOfStream, "Buffer already closed for writing");
             setInputMode();
             int remaining = len;
             while (remaining > 0) {
@@ -244,9 +243,7 @@ public class SharedOutputBuffer extends 
     public void write(int b) throws IOException {
         this.lock.lock();
         try {
-            if (this.shutdown || this.endOfStream) {
-                throw new IllegalStateException("Buffer already closed for writing");
-            }
+            Asserts.check(!this.shutdown && !this.endOfStream, "Buffer already closed for writing");
             setInputMode();
             if (!this.buffer.hasRemaining()) {
                 flushContent();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/RequestExecutionHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/RequestExecutionHandler.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/RequestExecutionHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/RequestExecutionHandler.java Tue Dec 18 16:12:13 2012
@@ -39,6 +39,7 @@ import org.apache.http.nio.protocol.Http
 import org.apache.http.nio.protocol.NHttpRequestExecutionHandler;
 import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Asserts;
 import org.apache.http.util.EntityUtils;
 
 @Deprecated
@@ -55,9 +56,7 @@ abstract class RequestExecutionHandler
 
         @SuppressWarnings("unchecked")
         Queue<Job> queue = (Queue<Job>) context.getAttribute("queue");
-        if (queue == null) {
-            throw new IllegalStateException("Queue is null");
-        }
+        Asserts.notNull(queue, "Queue");
 
         Job testjob = queue.poll();
         context.setAttribute("job", testjob);
@@ -77,9 +76,7 @@ abstract class RequestExecutionHandler
 
     public void handleResponse(final HttpResponse response, final HttpContext context) {
         Job testjob = (Job) context.removeAttribute("job");
-        if (testjob == null) {
-            throw new IllegalStateException("TestJob is null");
-        }
+        Asserts.notNull(testjob, "Test job");
 
         int statusCode = response.getStatusLine().getStatusCode();
         String content = null;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestThrottlingNHttpHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestThrottlingNHttpHandlers.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestThrottlingNHttpHandlers.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestThrottlingNHttpHandlers.java Tue Dec 18 16:12:13 2012
@@ -90,6 +90,7 @@ import org.apache.http.nio.testserver.Lo
 import org.apache.http.nio.testserver.LoggingServerConnectionFactory;
 import org.apache.http.nio.testserver.SimpleEventListener;
 import org.apache.http.nio.testserver.SimpleHttpRequestHandlerResolver;
+import org.apache.http.util.Asserts;
 import org.apache.http.util.EncodingUtils;
 import org.junit.After;
 import org.junit.Assert;
@@ -695,9 +696,7 @@ public class TestThrottlingNHttpHandlers
 
                 @SuppressWarnings("unchecked")
                 Queue<Job> queue = (Queue<Job>) context.getAttribute("queue");
-                if (queue == null) {
-                    throw new IllegalStateException("Queue is null");
-                }
+                Asserts.notNull(queue, "Queue");
 
                 Job testjob = queue.poll();
                 context.setAttribute("job", testjob);
@@ -720,9 +719,7 @@ public class TestThrottlingNHttpHandlers
 
             public void handleResponse(final HttpResponse response, final HttpContext context) {
                 Job testjob = (Job) context.removeAttribute("job");
-                if (testjob == null) {
-                    throw new IllegalStateException("TestJob is null");
-                }
+                Asserts.notNull(testjob, "Test job");
 
                 int statusCode = response.getStatusLine().getStatusCode();
                 String content = null;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/ContentEncoderMock.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/ContentEncoderMock.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/ContentEncoderMock.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/util/ContentEncoderMock.java Tue Dec 18 16:12:13 2012
@@ -34,6 +34,7 @@ import java.nio.channels.WritableByteCha
 import org.apache.http.impl.io.HttpTransportMetricsImpl;
 import org.apache.http.impl.nio.codecs.AbstractContentEncoder;
 import org.apache.http.nio.reactor.SessionOutputBuffer;
+import org.apache.http.util.Asserts;
 
 public class ContentEncoderMock extends AbstractContentEncoder {
 
@@ -61,9 +62,7 @@ public class ContentEncoderMock extends 
         if (src == null) {
             return 0;
         }
-        if (this.completed) {
-            throw new IllegalStateException("Decoding process already completed");
-        }
+        Asserts.check(!this.completed, "Decoding process already completed");
         return this.channel.write(src);
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/ProtocolVersion.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/ProtocolVersion.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/ProtocolVersion.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/ProtocolVersion.java Tue Dec 18 16:12:13 2012
@@ -200,10 +200,8 @@ public class ProtocolVersion implements 
      */
     public int compareToVersion(ProtocolVersion that) {
         Args.notNull(that, "Protocol version");
-        if (!this.protocol.equals(that.protocol)) {
-                throw new IllegalArgumentException("Versions for different protocols " +
-                		"cannot be compared. " + this + " " + that);
-        }
+        Args.check(this.protocol.equals(that.protocol),
+                "Versions for different protocols cannot be compared: %s %s", this, that);
         int delta = getMajor() - that.getMajor();
         if (delta == 0) {
             delta = getMinor() - that.getMinor();

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BasicHttpEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BasicHttpEntity.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BasicHttpEntity.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/BasicHttpEntity.java Tue Dec 18 16:12:13 2012
@@ -33,6 +33,7 @@ import java.io.OutputStream;
 
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 /**
  * A generic streamed, non-repeatable entity that obtains its content
@@ -70,11 +71,8 @@ public class BasicHttpEntity extends Abs
      *          if the content has not been provided
      */
     public InputStream getContent() throws IllegalStateException {
-        if (this.content == null) {
-            throw new IllegalStateException("Content has not been provided");
-        }
+        Asserts.check(this.content != null, "Content has not been provided");
         return this.content;
-
     }
 
     /**

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java Tue Dec 18 16:12:13 2012
@@ -43,6 +43,7 @@ import org.apache.http.io.SessionOutputB
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 /**
  * Implementation of a client-side HTTP connection that can be bound to an
@@ -66,16 +67,12 @@ public class SocketHttpClientConnection
     }
 
     protected void assertNotOpen() {
-        if (this.open) {
-            throw new IllegalStateException("Connection is already open");
-        }
+        Asserts.check(!this.open, "Connection is already open");
     }
 
     @Override
     protected void assertOpen() {
-        if (!this.open) {
-            throw new IllegalStateException("Connection is not open");
-        }
+        Asserts.check(this.open, "Connection is not open");
     }
 
     /**

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java Tue Dec 18 16:12:13 2012
@@ -43,6 +43,7 @@ import org.apache.http.io.SessionOutputB
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 /**
  * Implementation of a server-side HTTP connection that can be bound to a
@@ -65,16 +66,12 @@ public class SocketHttpServerConnection 
     }
 
     protected void assertNotOpen() {
-        if (this.open) {
-            throw new IllegalStateException("Connection is already open");
-        }
+        Asserts.check(!this.open, "Connection is already open");
     }
 
     @Override
     protected void assertOpen() {
-        if (!this.open) {
-            throw new IllegalStateException("Connection is not open");
-        }
+        Asserts.check(this.open, "Connection is not open");
     }
 
     /**

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicListHeaderIterator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicListHeaderIterator.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicListHeaderIterator.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/BasicListHeaderIterator.java Tue Dec 18 16:12:13 2012
@@ -34,6 +34,7 @@ import org.apache.http.Header;
 import org.apache.http.HeaderIterator;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 /**
  * Implementation of a {@link HeaderIterator} based on a {@link List}.
@@ -178,10 +179,7 @@ public class BasicListHeaderIterator imp
      */
     public void remove()
         throws UnsupportedOperationException {
-
-        if (this.lastIndex < 0) {
-            throw new IllegalStateException("No header to remove.");
-        }
+        Asserts.check(this.lastIndex >= 0, "No header to remove");
         this.allHeaders.remove(this.lastIndex);
         this.lastIndex = -1;
         this.currentIndex--; // adjust for the removed element

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java Tue Dec 18 16:12:13 2012
@@ -43,6 +43,7 @@ import java.util.concurrent.locks.Reentr
 import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.concurrent.FutureCallback;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 /**
  * Abstract synchronous (blocking) pool of connections.
@@ -153,9 +154,7 @@ public abstract class AbstractConnPool<T
      */
     public Future<E> lease(final T route, final Object state, final FutureCallback<E> callback) {
         Args.notNull(route, "Route");
-        if (this.isShutDown) {
-            throw new IllegalStateException("Connection pool shut down");
-        }
+        Asserts.check(!this.isShutDown, "Connection pool shut down");
         return new PoolEntryFuture<E>(this.lock, callback) {
 
             @Override
@@ -206,9 +205,7 @@ public abstract class AbstractConnPool<T
             RouteSpecificPool<T, C, E> pool = getPool(route);
             E entry = null;
             while (entry == null) {
-                if (this.isShutDown) {
-                    throw new IllegalStateException("Connection pool shut down");
-                }
+                Asserts.check(!this.isShutDown, "Connection pool shut down");
                 for (;;) {
                     entry = pool.getFree(state);
                     if (entry == null) {

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/pool/RouteSpecificPool.java Tue Dec 18 16:12:13 2012
@@ -33,6 +33,7 @@ import java.util.Set;
 
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.util.Args;
+import org.apache.http.util.Asserts;
 
 @NotThreadSafe
 abstract class RouteSpecificPool<T, C, E extends PoolEntry<T, C>> {
@@ -119,10 +120,7 @@ abstract class RouteSpecificPool<T, C, E
     public void free(final E entry, boolean reusable) {
         Args.notNull(entry, "Pool entry");
         boolean found = this.leased.remove(entry);
-        if (!found) {
-            throw new IllegalStateException("Entry " + entry +
-                    " has not been leased from this pool");
-        }
+        Asserts.check(found, "Entry %s has not been leased from this pool", entry);
         if (reusable) {
             this.available.addFirst(entry);
         }

Modified: 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=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Args.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Args.java Tue Dec 18 16:12:13 2012
@@ -37,6 +37,12 @@ public class Args {
         }
     }
     
+    public static void check(boolean expression, final String message, final Object... args) {
+        if (!expression) {
+            throw new IllegalArgumentException(String.format(message, args));
+        }
+    }
+
     public static <T> T notNull(final T argument, final String name) {
         if (argument == null) {
             throw new IllegalArgumentException(name + " may not be null");

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Asserts.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Asserts.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Asserts.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/util/Asserts.java Tue Dec 18 16:12:13 2012
@@ -35,6 +35,12 @@ public class Asserts {
         }
     }
     
+    public static void check(boolean expression, final String message, final Object... args) {
+        if (!expression) {
+            throw new IllegalStateException(String.format(message, args));
+        }
+    }
+
     public static void notNull(final Object object, final String name) {
         if (object == null) {
             throw new IllegalStateException(name + " is null");

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/HttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/HttpServer.java?rev=1423508&r1=1423507&r2=1423508&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/HttpServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/HttpServer.java Tue Dec 18 16:12:13 2012
@@ -53,6 +53,7 @@ import org.apache.http.protocol.Response
 import org.apache.http.protocol.ResponseDate;
 import org.apache.http.protocol.ResponseServer;
 import org.apache.http.protocol.UriHttpRequestHandlerMapper;
+import org.apache.http.util.Asserts;
 
 public class HttpServer {
 
@@ -117,9 +118,7 @@ public class HttpServer {
     }
 
     public void start() {
-        if (this.listener != null) {
-            throw new IllegalStateException("Listener already running");
-        }
+        Asserts.check(this.listener == null, "Listener already running");
         this.listener = new Thread(new Runnable() {
 
             public void run() {



Mime
View raw message