hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r539756 - /jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java
Date Sat, 19 May 2007 14:16:10 GMT
Author: rolandw
Date: Sat May 19 07:16:10 2007
New Revision: 539756

URL: http://svn.apache.org/viewvc?view=rev&rev=539756
Log:
improved check for cyclic defaults in BasicHttpParams, but the feature remains unpredictable

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java?view=diff&rev=539756&r1=539755&r2=539756
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/BasicHttpParams.java
Sat May 19 07:16:10 2007
@@ -68,7 +68,7 @@
      */
     public BasicHttpParams(final HttpParams defaults) {
         super();
-        this.defaults = defaults; 
+        setDefaults(defaults); // perform ancestor check
     }
     
     public BasicHttpParams() {
@@ -80,6 +80,19 @@
     }
     
     public synchronized void setDefaults(final HttpParams params) {
+
+        // check we're not becoming our own defaults, directly or indirectly
+        // that would trigger an endless loop when looking up an unknown param
+        HttpParams ancestor = params;
+        while (ancestor != null) {
+            // check for object identity, not .equals
+            if (ancestor == this) {
+                throw new IllegalArgumentException
+                    ("cyclic default params detected");
+            }
+            ancestor = ancestor.getDefaults();
+        }
+
         this.defaults = params;
     }
     
@@ -94,7 +107,7 @@
             return param;
         } else {
             // If not, see if defaults are available
-            if (this.defaults != null && this.defaults != this) {
+            if (this.defaults != null) {
                 // Return default parameter value
                 return this.defaults.getParameter(name);
             } else {



Mime
View raw message