Author: markt
Date: Tue Jun 23 10:48:53 2009
New Revision: 787627

URL: http://svn.apache.org/viewvc?rev=787627&view=rev
Log:
Only copy the original parameters is debug is enabled. Otherwise, live with the 
corruption but tell user how to get non-corrupted data

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java?rev=787627&r1=787626&r2=787627&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/Parameters.java Tue Jun 23 
10:48:53 2009
@@ -398,14 +398,18 @@
             }
             tmpName.setBytes( bytes, nameStart, nameEnd-nameStart );
             tmpValue.setBytes( bytes, valStart, valEnd-valStart );
-            try {
-                // Take copies as if anything goes wrong originals will be
-                // corrupted. This means original values can be logged
-                origName.append(bytes, nameStart, nameEnd-nameStart);
-                origValue.append(bytes, valStart, valEnd-valStart);
-            } catch (IOException ioe) {
-                // Should never happen...
-                log.error("Error copying parameters", ioe);
+            
+            // Take copies as if anything goes wrong originals will be
+            // corrupted. This means original values can be logged.
+            // For performance - only done for debug
+            if (log.isDebugEnabled()) {
+                try {
+                    origName.append(bytes, nameStart, nameEnd-nameStart);
+                    origValue.append(bytes, valStart, valEnd-valStart);
+                } catch (IOException ioe) {
+                    // Should never happen...
+                    log.error("Error copying parameters", ioe);
+                }
             }
             
             try {
@@ -414,21 +418,31 @@
                 StringBuilder msg =
                     new StringBuilder("Parameters: Character decoding 
failed.");
                 msg.append(" Parameter '");
-                msg.append(origName.toString());
-                msg.append("' with value '");
-                msg.append(origValue.toString());
-                msg.append("' has been ignored.");
                 if (log.isDebugEnabled()) {
+                    msg.append(origName.toString());
+                    msg.append("' with value '");
+                    msg.append(origValue.toString());
+                    msg.append("' has been ignored.");
                     log.debug(msg, e);
                 } else {
+                    msg.append(tmpName.toString());
+                    msg.append("' with value '");
+                    msg.append(tmpValue.toString());
+                    msg.append("' has been ignored. Note that the name and ");
+                    msg.append("value quoted here may corrupted due to the ");
+                    msg.append("failed decoding. Use debug level logging to ");
+                    msg.append("see the original, non-corrupted values.");
                     log.warn(msg);
                 }
             }
 
             tmpName.recycle();
             tmpValue.recycle();
-            origName.recycle();
-            origValue.recycle();
+            // Only recycle copies if we used them
+            if (log.isDebugEnabled()) {
+                origName.recycle();
+                origValue.recycle();
+            }
         } while( pos<end );
     }
 



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

Reply via email to