Author: kkolinko
Date: Wed Jun 15 12:20:01 2011
New Revision: 1136010

URL: http://svn.apache.org/viewvc?rev=1136010&view=rev
Log:
Improve system property replacement code in ClassLoaderLogManager of Tomcat 
JULI.
Fixes https://issues.apache.org/bugzilla/show_bug.cgi?id=51249
1. Do not use recursion.
2. Do not stop on the first unrecognized property, but continue with the rest 
of the string.
3. Do not call System.getProperty() on an empty key, because it throws 
IllegalArgumentException. Threat "${}" as unrecognized property.
It is backport of r1133857

Added:
    tomcat/tc6.0.x/trunk/test/org/apache/juli/
      - copied from r1136008, tomcat/trunk/test/org/apache/juli/
Modified:
    tomcat/tc6.0.x/trunk/STATUS.txt
    tomcat/tc6.0.x/trunk/java/org/apache/juli/ClassLoaderLogManager.java
    tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1136010&r1=1136009&r2=1136010&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Wed Jun 15 12:20:01 2011
@@ -157,23 +157,6 @@ PATCHES PROPOSED TO BACKPORT:
   +1: markt, rjung
   -1:
 
-* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51249
-  Improve system property replacement code in ClassLoaderLogManager of Tomcat 
JULI.
-  1) Tests
-   svn copy "^/tomcat/trunk/test/org/apache/juli" "test/org/apache/juli"
-  2) Patch (backport of r1133857)
-   
http://people.apache.org/~kkolinko/patches/2011-06-09_tc6_ClassLoaderLogManager.patch
-  It fixes the following issues:
-   1. Correctly search for "}" so properties in the form "}${property}" are
-   correctly replaced. This is BZ 51249.
-   Note, that ${property}${property} is already working in 6.0.32, thanks to 
recursion.
-   2. Do not stop processing on first unrecognized property.
-   The old code did not perform recursion if replacement failed.
-   3. Do not call System.getProperty() for empty property name,
-   which was throwing IllegalArgumentException.
- +1: kkolinko, jung, markt
- -1:
-
 * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51306.
   Avoid NPE when handleSESSION_EXPIRED is processed while 
handleSESSION_CREATED is being processed. 
   -setMaxInactiveInterval is not added to DeltaRequest in 
handleSESSION_CREATED.

Modified: tomcat/tc6.0.x/trunk/java/org/apache/juli/ClassLoaderLogManager.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/juli/ClassLoaderLogManager.java?rev=1136010&r1=1136009&r2=1136010&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/juli/ClassLoaderLogManager.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/juli/ClassLoaderLogManager.java Wed 
Jun 15 12:20:01 2011
@@ -559,21 +559,29 @@ public class ClassLoaderLogManager exten
      */
     protected String replace(String str) {
         String result = str;
-        int pos_start = result.indexOf("${");
-        if (pos_start != -1) {
-            int pos_end = result.indexOf('}');
-            if (pos_end != -1) {
-                String propName = result.substring(pos_start + 2, pos_end);
-                String replacement = System.getProperty(propName);
+        int pos_start = str.indexOf("${");
+        if (pos_start >= 0) {
+            StringBuilder builder = new StringBuilder();
+            int pos_end = -1;
+            while (pos_start >= 0) {
+                builder.append(str, pos_end + 1, pos_start);
+                pos_end = str.indexOf('}', pos_start + 2);
+                if (pos_end < 0) {
+                    pos_end = pos_start - 1;
+                    break;
+                }
+                String propName = str.substring(pos_start + 2, pos_end);
+                String replacement = propName.length() > 0 ? System
+                        .getProperty(propName) : null;
                 if (replacement != null) {
-                    if(pos_start >0) {
-                        result = result.substring(0,pos_start) + 
-                            replacement + replace(result.substring(pos_end + 
1));
-                    } else {                       
-                        result = replacement + 
replace(result.substring(pos_end + 1));
-                    }
+                    builder.append(replacement);
+                } else {
+                    builder.append(str, pos_start, pos_end + 1);
                 }
+                pos_start = str.indexOf("${", pos_end + 1);
             }
+            builder.append(str, pos_end + 1, str.length());
+            result = builder.toString();
         }
         return result;
     }

Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=1136010&r1=1136009&r2=1136010&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Wed Jun 15 12:20:01 2011
@@ -115,6 +115,11 @@
         than as a String. (markt)
       </fix>
       <fix>
+        <bug>51249</bug>: Improve system property replacement code
+        in ClassLoaderLogManager of Tomcat JULI to cover some corner cases.
+        (kkolinko)
+      </fix>
+      <fix>
         <bug>51315</bug>: Fix IAE when removing an authenticator valve from a
         container. Patch provided by Violeta Georgieva. (markt)
       </fix>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to