Bug 975731 - IllegalArgumentException thrown in ExoLogger when characters used in RegExps such as $,(,) are used in the message
IllegalArgumentException thrown in ExoLogger when characters used in RegExps ...
Status: VERIFIED
Product: JBoss Enterprise Portal Platform 6
Classification: JBoss
Component: Portal (Show other bugs)
6.0.0
Unspecified Unspecified
unspecified Severity unspecified
: ER01
: 6.1.1
Assigned To: Default User
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-06-19 04:44 EDT by Adam Kovari
Modified: 2015-08-31 23:04 EDT (History)
7 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
EXO WCM JIRA KER-247 None None None Never

  None (edit)
Description Adam Kovari 2013-06-19 04:44:31 EDT
Description of problem:
    ExoLogger.getLogger(ExoLoggerTest.class).info("Hello {}", "$myself");

causes:

java.lang.IllegalArgumentException: Illegal group reference
    at java.util.regex.Matcher.appendReplacement(Matcher.java:808)
    at java.util.regex.Matcher.replaceFirst(Matcher.java:955)
    at org.exoplatform.services.log.impl.LogMessageFormatter.getMessage(LogMessageFormatter.java:44)
    at org.exoplatform.services.log.impl.SimpleExoLog.info(SimpleExoLog.java:157)


Version-Release number of selected component (if applicable):
JPP 6

How reproducible:
Always

Steps to Reproduce:
1. ExoLogger.getLogger(ExoLoggerTest.class).info("Hello {}", "$myself");

Actual results:
Exception thrown

Expected results:
Message to be properly replaced

Additional info:
Proposed fix:

diff --git a/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/LogMessageFormatter.java b/exo.kernel.commons/src/main/java/org/exoplatform/services/log
index faed574..3c18d59 100644
--- a/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/LogMessageFormatter.java
+++ b/exo.kernel.commons/src/main/java/org/exoplatform/services/log/impl/LogMessageFormatter.java
@@ -19,6 +19,7 @@
 package org.exoplatform.services.log.impl;
 
 import java.util.regex.Pattern;
+import java.util.regex.Matcher;
 
 /**
  * Simple class to provide format parsing of log messages similar to what slf4j library does.
@@ -41,7 +42,7 @@ public class LogMessageFormatter
             if (i != argsArray.length - 1 || !(argsArray[i] instanceof Throwable))
             {
                String message = String.valueOf(argsArray[i]);
-               str = REPLACE_PATTERN.matcher(str).replaceFirst(message != null ? message : "null");
+               str = REPLACE_PATTERN.matcher(str).replaceFirst(message != null ? Matcher.quoteReplacement(message) : "null");
             }
          }
       }
diff --git a/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestLogMessageFormatter.java b/exo.kernel.commons/src/test/java/org/exoplatform/commons/util
index 4f4ebfe..06e1abf 100644
--- a/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestLogMessageFormatter.java
+++ b/exo.kernel.commons/src/test/java/org/exoplatform/commons/utils/TestLogMessageFormatter.java
@@ -73,4 +73,8 @@ public class TestLogMessageFormatter extends TestCase
          return "";
       }
    }
+   
+       public void testSpecialCharacterReplacement() throws Exception{
+               assertEquals("Hello, World $var", LogMessageFormatter.getMessage("Hello, World {}", "$var"));
+               assertEquals("Hello $foo and $bar", LogMessageFormatter.getMessage("Hello {} and {}", "$foo", "$bar"));
+       }   
 }
Comment 1 Thomas Heute 2013-06-19 05:28:15 EDT
eXo logger is a private logger and should not be used by customers. There are many other logger alternatives.

Any reason to use eXo logger here ?
Comment 4 Tomas Kyjovsky 2014-02-20 08:31:17 EST
Tested with the simplest-hello-world-portlet in 6.1.1.CR1.



ExoLogger.getLogger(SimplestHelloWorldPortlet.class).info("Hello {}", "$myself");

14:26:24,844 INFO  [org.jboss.quickstarts.portal.simplest.SimplestHelloWorldPortlet] (http-/0.0.0.0:8080-2) Hello $myself


ExoLogger.getLogger(SimplestHelloWorldPortlet.class).info("Hello {}", "$myself ()");

14:28:13,032 INFO  [org.jboss.quickstarts.portal.simplest.SimplestHelloWorldPortlet] (http-/0.0.0.0:8080-43) Hello $myself ()

Note You need to log in before you can comment on or make changes to this bug.