Author: rpopma
Date: Sat Jan 11 03:58:18 2014
New Revision: 1557307
URL: http://svn.apache.org/r1557307
Log:
LOG4J2-492 Fixed MalformedObjectNameException if context name contains '='
character.
Added:
logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/
logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
(with props)
Modified:
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
logging/log4j/log4j2/trunk/src/changes/changes.xml
Modified:
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java?rev=1557307&r1=1557306&r2=1557307&view=diff
==============================================================================
---
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
(original)
+++
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
Sat Jan 11 03:58:18 2014
@@ -74,14 +74,18 @@ public final class Server {
for (int i = 0; i < name.length(); i++) {
final char c = name.charAt(i);
switch (c) {
- case ',':
- case '=':
- case ':':
case '\\':
case '*':
case '?':
- sb.append('\\');
- needsQuotes = true;
+ case '\"':
+ sb.append('\\'); // quote, star, question & backslash must be
escaped
+ needsQuotes = true; // ... and can only appear in quoted value
+ break;
+ case ',':
+ case '=':
+ case ':':
+ needsQuotes = true; // no need to escape these, but value must
be quoted
+ break;
}
sb.append(c);
}
Added:
logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java?rev=1557307&view=auto
==============================================================================
---
logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
(added)
+++
logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
Sat Jan 11 03:58:18 2014
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.core.jmx;
+
+import static org.junit.Assert.*;
+
+import javax.management.ObjectName;
+
+import org.junit.Test;
+
+/**
+ * Unit tests for the Server class.
+ */
+public class ServerTest {
+
+ @Test
+ public void testEscapeQuotesButDoesNotEscapeEquals() throws Exception {
+ final String ctx = "WebAppClassLoader=1320771902@4eb9613e"; //
LOG4J2-492
+ final String ctxName = Server.escape(ctx);
+ assertEquals("\"WebAppClassLoader=1320771902@4eb9613e\"", ctxName);
+ new ObjectName(String.format(LoggerContextAdminMBean.PATTERN,
ctxName));
+ // no MalformedObjectNameException = success
+ }
+
+ @Test
+ public void testEscapeQuotesButDoesNotEscapeComma() throws Exception {
+ final String ctx = "a,b,c";
+ final String ctxName = Server.escape(ctx);
+ assertEquals("\"a,b,c\"", ctxName);
+ new ObjectName(String.format(LoggerContextAdminMBean.PATTERN,
ctxName));
+ // no MalformedObjectNameException = success
+ }
+
+ @Test
+ public void testEscapeQuotesButDoesNotEscapeColon() throws Exception {
+ final String ctx = "a:b:c";
+ final String ctxName = Server.escape(ctx);
+ assertEquals("\"a:b:c\"", ctxName);
+ new ObjectName(String.format(LoggerContextAdminMBean.PATTERN,
ctxName));
+ // no MalformedObjectNameException = success
+ }
+
+ @Test
+ public void testEscapeQuotesAndEscapesQuestion() throws Exception {
+ final String ctx = "a?c";
+ final String ctxName = Server.escape(ctx);
+ assertEquals("\"a\\?c\"", ctxName);
+ new ObjectName(String.format(LoggerContextAdminMBean.PATTERN,
ctxName));
+ // no MalformedObjectNameException = success
+ }
+
+ @Test
+ public void testEscapeQuotesAndEscapesStar() throws Exception {
+ final String ctx = "a*c";
+ final String ctxName = Server.escape(ctx);
+ assertEquals("\"a\\*c\"", ctxName);
+ new ObjectName(String.format(LoggerContextAdminMBean.PATTERN,
ctxName));
+ // no MalformedObjectNameException = success
+ }
+
+ @Test
+ public void testEscapeQuotesAndEscapesBackslash() throws Exception {
+ final String ctx = "a\\c";
+ final String ctxName = Server.escape(ctx);
+ assertEquals("\"a\\\\c\"", ctxName);
+ new ObjectName(String.format(LoggerContextAdminMBean.PATTERN,
ctxName));
+ // no MalformedObjectNameException = success
+ }
+
+ @Test
+ public void testEscapeQuotesAndEscapesQuote() throws Exception {
+ final String ctx = "a\"c";
+ final String ctxName = Server.escape(ctx);
+ assertEquals("\"a\\\"c\"", ctxName);
+ new ObjectName(String.format(LoggerContextAdminMBean.PATTERN,
ctxName));
+ // no MalformedObjectNameException = success
+ }
+}
Propchange:
logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/jmx/ServerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1557307&r1=1557306&r2=1557307&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat Jan 11 03:58:18 2014
@@ -21,6 +21,9 @@
</properties>
<body>
<release version="2.0-RC1" date="2013-MM-DD" description="Bug fixes and
enhancements">
+ <action issue="LOG4J2-492" dev="rpopma" type="fix" due-to="Shaddy
Baddah">
+ (JMX) Fixed MalformedObjectNameException if context name contains '='
character.
+ </action>
<action issue="LOG4J2-377" dev="rpopma" type="fix" due-to="Roland
Weiglhofer, Matt Sicker">
(OSGi) Fix NPE during shutdown.
</action>