You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2012/11/13 05:46:23 UTC

svn commit: r1408577 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java api/src/test/java/org/apache/logging/log4j/message/StructuredDataMessageTest.java src/changes/changes.xml

Author: rgoers
Date: Tue Nov 13 04:46:22 2012
New Revision: 1408577

URL: http://svn.apache.org/viewvc?rev=1408577&view=rev
Log:
Fix LOG4J2-114 - StructuredDataMessage was validating the length of the value instead of the key

Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
    logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/StructuredDataMessageTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java?rev=1408577&r1=1408576&r2=1408577&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java (original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java Tue Nov 13 04:46:22 2012
@@ -188,8 +188,8 @@ public class StructuredDataMessage exten
 
     @Override
     protected void validate(String key, String value) {
-        if (value.length() > MAX_LENGTH) {
-            throw new IllegalArgumentException("Structured data values are limited to 32 characters. key: " + key +
+        if (key.length() > MAX_LENGTH) {
+            throw new IllegalArgumentException("Structured data keys are limited to 32 characters. key: " + key +
                 " value: " + value);
         }
     }

Modified: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/StructuredDataMessageTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/StructuredDataMessageTest.java?rev=1408577&r1=1408576&r2=1408577&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/StructuredDataMessageTest.java (original)
+++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/message/StructuredDataMessageTest.java Tue Nov 13 04:46:22 2012
@@ -31,8 +31,16 @@ public class StructuredDataMessageTest {
         StructuredDataMessage msg = new StructuredDataMessage("MsgId@12345", testMsg, "Alert");
         msg.put("message", testMsg);
         msg.put("project", "Log4j");
+        msg.put("memo", "This is a very long test memo to prevent regression of LOG4J2-114");
         String result = msg.getFormattedMessage();
-        String expected = "Alert [MsgId@12345 message=\"Test message {}\" project=\"Log4j\"] Test message {}";
+        String expected = "Alert [MsgId@12345 memo=\"This is a very long test memo to prevent regression of LOG4J2-114\" message=\"Test message {}\" project=\"Log4j\"] Test message {}";
         assertEquals(expected, result);
     }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testMsgWithKeyTooLong() {
+        String testMsg = "Test message {}";
+        StructuredDataMessage msg = new StructuredDataMessage("MsgId@12345", testMsg, "Alert");
+        msg.put("This is a very long key that will violate the key length validation", "Testing");
+    }
 }

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1408577&r1=1408576&r2=1408577&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Tue Nov 13 04:46:22 2012
@@ -22,6 +22,12 @@
   </properties>
 
   <body>
+    <release version="2.0-beta4" date="TBD" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-114" dev="rgoers" type="fix" due-to="Arkin Yetis">
+        StructuredDataMessage was validating the length of the values in the event Map instead of the lengths
+        of the keys.
+      </action>
+    </release>
     <release version="2.0-beta3" date="2012-11-11" description= "Bug fixes and enhancements">
       <action issue="LOG4J2-108" dev="rgoers" type="fix">
         Fix NullPointerException in ClassLoaderContextSelector when no class is returned from