tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kkoli...@apache.org
Subject svn commit: r1133857 - in /tomcat/trunk: java/org/apache/juli/ClassLoaderLogManager.java test/org/apache/juli/TestClassLoaderLogManager.java webapps/docs/changelog.xml
Date Thu, 09 Jun 2011 13:20:10 GMT
Author: kkolinko
Date: Thu Jun  9 13:20:09 2011
New Revision: 1133857

URL: http://svn.apache.org/viewvc?rev=1133857&view=rev
Log:
https://issues.apache.org/bugzilla/show_bug.cgi?id=51249
Reimplement system properties replacement code in ClassLoaderLogManager of JULI
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.

Modified:
    tomcat/trunk/java/org/apache/juli/ClassLoaderLogManager.java
    tomcat/trunk/test/org/apache/juli/TestClassLoaderLogManager.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/juli/ClassLoaderLogManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/juli/ClassLoaderLogManager.java?rev=1133857&r1=1133856&r2=1133857&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/juli/ClassLoaderLogManager.java (original)
+++ tomcat/trunk/java/org/apache/juli/ClassLoaderLogManager.java Thu Jun  9 13:20:09 2011
@@ -566,25 +566,32 @@ 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('}', pos_start);
-            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;
     }
-    
 
     // ---------------------------------------------------- LogNode Inner Class
 

Modified: tomcat/trunk/test/org/apache/juli/TestClassLoaderLogManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/juli/TestClassLoaderLogManager.java?rev=1133857&r1=1133856&r2=1133857&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/juli/TestClassLoaderLogManager.java (original)
+++ tomcat/trunk/test/org/apache/juli/TestClassLoaderLogManager.java Thu Jun  9 13:20:09 2011
@@ -28,8 +28,8 @@ public class TestClassLoaderLogManager e
         ClassLoaderLogManager logManager = new ClassLoaderLogManager();
         assertEquals("", logManager.replace(""));
         assertEquals("${", logManager.replace("${"));
-        assertEquals("${undefinedsystemproperty}",
-                logManager.replace("${undefinedsystemproperty}"));
+        assertEquals("${undefinedproperty}",
+                logManager.replace("${undefinedproperty}"));
         assertEquals(
                 System.getProperty("line.separator")
                         + System.getProperty("path.separator")
@@ -46,6 +46,13 @@ public class TestClassLoaderLogManager e
         assertEquals(
                 "%{file.separator}" + System.getProperty("file.separator"),
                 logManager.replace("%{file.separator}${file.separator}"));
+        assertEquals(
+                System.getProperty("file.separator") + "${undefinedproperty}"
+                        + System.getProperty("file.separator"),
+                logManager
+                        .replace("${file.separator}${undefinedproperty}${file.separator}"));
+        assertEquals("${}" + System.getProperty("path.separator"),
+                logManager.replace("${}${path.separator}"));
     }
 
 }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1133857&r1=1133856&r2=1133857&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Jun  9 13:20:09 2011
@@ -76,6 +76,11 @@
         files in parallel. Apache Tomcat does not do this but products that
         embed it may. (markt)
       </fix>
+      <fix>
+        <bug>51249</bug>: Further improve system property replacement code
+        in ClassLoaderLogManager of Tomcat JULI to cover some corner cases.
+        (kkolinko)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">
@@ -140,7 +145,7 @@
       </fix>
       <fix>
         <bug>51249</bug>: Correct ClassLoaderLogManager system property
-        replacement code so properties of the form ${...}${...} can be used
+        replacement code so properties of the form "}${...}" can be used
         without error. (markt) 
       </fix>
       <fix>



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


Mime
View raw message