hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r390703 - in /jakarta/httpcomponents/trunk/http-core/src: java/org/apache/http/ java/org/apache/http/entity/ java/org/apache/http/impl/ java/org/apache/http/impl/io/ java/org/apache/http/io/ java/org/apache/http/message/ java/org/apache/htt...
Date Sat, 01 Apr 2006 17:35:48 GMT
Author: olegk
Date: Sat Apr  1 09:35:45 2006
New Revision: 390703

URL: http://svn.apache.org/viewcvs?rev=390703&view=rev
Log:
Fixed some potential problems reported by Findbugs

Modified:
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HeaderElement.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HttpHost.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/ProxyHost.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/entity/FileEntity.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpParams.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpGet.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpHead.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpPost.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/params/HttpParams.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/HTTP.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/util/EntityUtils.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/util/LangUtils.java
    jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/TestHttpHost.java

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HeaderElement.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HeaderElement.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HeaderElement.java (original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HeaderElement.java Sat
Apr  1 09:35:45 2006
@@ -106,7 +106,8 @@
         this.name = name;
         this.value = value;
         if (parameters != null) {
-            this.parameters = parameters;
+            this.parameters = new NameValuePair[parameters.length];
+            System.arraycopy(parameters, 0, this.parameters, 0, parameters.length);
         } else {
             this.parameters = new NameValuePair[] {};
         }
@@ -147,7 +148,9 @@
      * @return parameters as an array of {@link NameValuePair}s
      */
     public NameValuePair[] getParameters() {
-        return this.parameters;
+        NameValuePair[] acopy = new NameValuePair[this.parameters.length]; 
+        System.arraycopy(this.parameters, 0, acopy, 0, this.parameters.length);
+        return acopy;
     }
 
     // --------------------------------------------------------- Public Methods

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HttpHost.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HttpHost.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HttpHost.java (original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/HttpHost.java Sat Apr
 1 09:35:45 2006
@@ -43,7 +43,7 @@
  * 
  * @since 3.0 
  */
-public class HttpHost implements Cloneable {
+public class HttpHost {
 
     /** The host to use. */
     private String hostname = null;
@@ -109,13 +109,6 @@
         this.scheme = httphost.scheme;
     }
 
-    /**
-     * @see java.lang.Object#clone()
-     */
-    public Object clone() {
-        return new HttpHost(this);
-    }    
-    
     /**
      * Returns the host name (IP or DNS name).
      * 

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/ProxyHost.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/ProxyHost.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/ProxyHost.java (original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/ProxyHost.java Sat Apr
 1 09:35:45 2006
@@ -70,11 +70,4 @@
         this(hostname, -1);
     }
     
-    /**
-     * @see java.lang.Object#clone()
-     */
-    public Object clone() {
-        return new ProxyHost(this);
-    }    
-    
 }

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/entity/FileEntity.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/entity/FileEntity.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/entity/FileEntity.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/entity/FileEntity.java
Sat Apr  1 09:35:45 2006
@@ -74,12 +74,16 @@
             throw new IllegalArgumentException("Output stream may not be null");
         }
         InputStream instream = new FileInputStream(this.file);
-        byte[] tmp = new byte[4096];
-        int l;
-        while ((l = instream.read(tmp)) != -1) {
-            outstream.write(tmp, 0, l);
+        try {
+            byte[] tmp = new byte[4096];
+            int l;
+            while ((l = instream.read(tmp)) != -1) {
+                outstream.write(tmp, 0, l);
+            }
+            outstream.flush();
+        } finally {
+            instream.close();
         }
-        outstream.flush();
     }
 
     /**

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpParams.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpParams.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpParams.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpParams.java
Sat Apr  1 09:35:45 2006
@@ -46,7 +46,7 @@
  * 
  * @since 3.0
  */
-public class DefaultHttpParams implements HttpParams, Serializable, Cloneable {
+public class DefaultHttpParams implements HttpParams, Serializable {
 
 	static final long serialVersionUID = -8296449161405728403L;
 	
@@ -171,7 +171,7 @@
     }
     
     public HttpParams setBooleanParameter(final String name, boolean value) {
-        setParameter(name, new Boolean(value));
+        setParameter(name, value ? Boolean.TRUE : Boolean.FALSE);
         return this;
     }
 
@@ -198,18 +198,4 @@
         this.parameters = null;
     }
 
-    /**
-     * Clones this collection of parameters. Please note that paramter values
-     * themselves are not cloned. 
-     * 
-     * @see java.io.Serializable
-     * @see java.lang.Object#clone()
-     */
-    public Object clone() {
-        DefaultHttpParams clone = new DefaultHttpParams(this.defaults);
-        if (this.parameters != null) {
-            clone.parameters = (HashMap)this.parameters.clone(); 
-        }
-        return clone;
-    }
 }

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java
Sat Apr  1 09:35:45 2006
@@ -47,6 +47,8 @@
  */
 public abstract class AbstractHttpDataTransmitter implements HttpDataTransmitter {
 
+    private static final byte[] CRLF = new byte[] {HTTP.CR, HTTP.LF};
+    
     private static int MAX_CHUNK = 256;
     
     private OutputStream outstream;
@@ -123,7 +125,7 @@
         if (s.length() > 0) {
             write(s.getBytes(this.charset));
         }
-        write(HTTP.CRLF);
+        write(CRLF);
     }
     
     public void writeLine(final CharArrayBuffer s) throws IOException {
@@ -151,7 +153,7 @@
             byte[] tmp = s.toString().getBytes(this.charset);
             write(tmp);
         }
-        write(HTTP.CRLF);
+        write(CRLF);
     }
     
     public void reset(final HttpParams params) {

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/ChunkedInputStream.java
Sat Apr  1 09:35:45 2006
@@ -318,7 +318,9 @@
     }
 
     public Header[] getFooters() {
-        return this.footers;
+        Header[] acopy = new Header[this.footers.length]; 
+        System.arraycopy(this.footers, 0, acopy, 0, this.footers.length);
+        return acopy;
     }
     
     /**

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpGet.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpGet.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpGet.java (original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpGet.java Sat
Apr  1 09:35:45 2006
@@ -40,7 +40,7 @@
  */
 public class HttpGet extends BasicHttpRequest {
 
-    public static String METHOD_NAME = "GET";
+    public final static String METHOD_NAME = "GET";
     
     public HttpGet(final String uri) {
         super(METHOD_NAME, uri);

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpHead.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpHead.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpHead.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpHead.java
Sat Apr  1 09:35:45 2006
@@ -40,7 +40,7 @@
  */
 public class HttpHead extends BasicHttpRequest {
 
-    public static String METHOD_NAME = "HEAD";
+    public final static String METHOD_NAME = "HEAD";
     
     public HttpHead(final String uri) {
         super(METHOD_NAME, uri);

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpPost.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpPost.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpPost.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/message/HttpPost.java
Sat Apr  1 09:35:45 2006
@@ -40,7 +40,7 @@
  */
 public class HttpPost extends BasicHttpEntityEnclosingRequest {
 
-    public static String METHOD_NAME = "POST";
+    public final static String METHOD_NAME = "POST";
     
     public HttpPost(final String uri) {
         super(METHOD_NAME, uri);

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/params/HttpParams.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/params/HttpParams.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/params/HttpParams.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/params/HttpParams.java
Sat Apr  1 09:35:45 2006
@@ -228,12 +228,4 @@
      */
     boolean isParameterFalse(String name);
 
-    /**
-     * Clones this collection of parameters. This method may produce a shallow copy
-     * of the parameter collection if appropriate. 
-     * 
-     * @see java.lang.Object#clone()
-     */
-    Object clone();
-    
 }

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/HTTP.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/HTTP.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/HTTP.java (original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/protocol/HTTP.java Sat
Apr  1 09:35:45 2006
@@ -44,7 +44,6 @@
     public static final int LF = 10; // <US-ASCII LF, linefeed (10)>
     public static final int SP = 32; // <US-ASCII SP, space (32)>
     public static final int HT = 9;  // <US-ASCII HT, horizontal-tab (9)>
-    public static final byte[] CRLF = new byte[] {CR, LF};
 
     /** HTTP header definitions */ 
     public static final String TRANSFER_ENCODING = "Transfer-Encoding";

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/util/EntityUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/util/EntityUtils.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/util/EntityUtils.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/util/EntityUtils.java
Sat Apr  1 09:35:45 2006
@@ -71,10 +71,14 @@
             i = 4096;
         }
         ByteArrayBuffer buffer = new ByteArrayBuffer(i);
-        byte[] tmp = new byte[4096];
-        int l;
-        while((l = instream.read(tmp)) != -1) {
-        	buffer.append(tmp, 0, l);
+        try {
+            byte[] tmp = new byte[4096];
+            int l;
+            while((l = instream.read(tmp)) != -1) {
+                buffer.append(tmp, 0, l);
+            }
+        } finally {
+            instream.close();
         }
         return buffer.toByteArray();
     }
@@ -121,10 +125,14 @@
         }
         Reader reader = new InputStreamReader(instream, charset);
         CharArrayBuffer buffer = new CharArrayBuffer(i); 
-        char[] tmp = new char[1024];
-        int l;
-        while((l = reader.read(tmp)) != -1) {
-            buffer.append(tmp, 0, l);
+        try {
+            char[] tmp = new char[1024];
+            int l;
+            while((l = reader.read(tmp)) != -1) {
+                buffer.append(tmp, 0, l);
+            }
+        } finally {
+            reader.close();
         }
         return buffer.toString();
     }

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/util/LangUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/util/LangUtils.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/util/LangUtils.java (original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/util/LangUtils.java Sat
Apr  1 09:35:45 2006
@@ -39,8 +39,8 @@
  */
 public class LangUtils {
     
-    public static int HASH_SEED = 17;
-    public static int HASH_OFFSET = 37;
+    public static final int HASH_SEED = 17;
+    public static final int HASH_OFFSET = 37;
     
     private LangUtils() {
     }

Modified: jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/TestHttpHost.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/TestHttpHost.java?rev=390703&r1=390702&r2=390703&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/TestHttpHost.java (original)
+++ jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/TestHttpHost.java Sat
Apr  1 09:35:45 2006
@@ -179,12 +179,4 @@
         assertEquals("somehost:8888", host4.toHostString());
     }
 
-    public void testClone() {
-        HttpHost host1 = new HttpHost("somehost", 8888, Scheme.getScheme("http"));
-        HttpHost host2 = (HttpHost) host1.clone(); 
-        assertEquals(host1, host2);
-        ProxyHost proxyhost1 = new ProxyHost("somehost", 8888);
-        ProxyHost proxyhost2 = (ProxyHost) proxyhost1.clone(); 
-        assertEquals(proxyhost1, proxyhost2);
-    }
 }



Mime
View raw message