You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/03/16 14:38:21 UTC

[04/50] logging-log4j2 git commit: LOG4J2-1310 - JndiLookup mindlessly casts to String and should use String.valueOf().

LOG4J2-1310 - JndiLookup mindlessly casts to String and should use String.valueOf().


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/c6318b63
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c6318b63
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c6318b63

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: c6318b63818427833db2dc08389c463102c1a66e
Parents: ed6c608
Author: Matt Sicker <bo...@gmail.com>
Authored: Tue Mar 8 11:24:17 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Tue Mar 8 11:24:17 2016 -0600

----------------------------------------------------------------------
 .../logging/log4j/core/lookup/JndiLookup.java     |  2 +-
 .../logging/log4j/core/lookup/JndiLookupTest.java | 18 ++++++++++++++++++
 src/changes/changes.xml                           |  3 +++
 3 files changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c6318b63/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
index d7d50cb..1cd4290 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java
@@ -52,7 +52,7 @@ public class JndiLookup extends AbstractLookup {
         final String jndiName = convertJndiName(key);
         final JndiManager jndiManager = JndiManager.getDefaultManager();
         try {
-            return jndiManager.lookup(jndiName);
+            return String.valueOf(jndiManager.lookup(jndiName));
         } catch (final NamingException e) {
             LOGGER.warn(LOOKUP, "Error looking up JNDI resource [{}].", jndiName, e);
             return null;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c6318b63/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/JndiLookupTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/JndiLookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/JndiLookupTest.java
index 97f6a3b..1211cf5 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/JndiLookupTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/JndiLookupTest.java
@@ -16,6 +16,8 @@
  */
 package org.apache.logging.log4j.core.lookup;
 
+import java.util.Arrays;
+import java.util.Collection;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
@@ -34,6 +36,10 @@ public class JndiLookupTest {
 
     private static final String TEST_CONTEXT_RESOURCE_NAME = "logging/context-name";
     private static final String TEST_CONTEXT_NAME = "app-1";
+    private static final String TEST_INTEGRAL_NAME = "int-value";
+    private static final int TEST_INTEGRAL_VALUE = 42;
+    private static final String TEST_STRINGS_NAME = "string-collection";
+    private static final Collection<String> TEST_STRINGS_COLLECTION = Arrays.asList("one", "two", "three");
 
     private Context context;
 
@@ -42,6 +48,8 @@ public class JndiLookupTest {
         MockContextFactory.setAsInitial();
         context = new InitialContext();
         context.bind(JndiLookup.CONTAINER_JNDI_RESOURCE_PATH_PREFIX + TEST_CONTEXT_RESOURCE_NAME, TEST_CONTEXT_NAME);
+        context.bind(JndiLookup.CONTAINER_JNDI_RESOURCE_PATH_PREFIX + TEST_INTEGRAL_NAME, TEST_INTEGRAL_VALUE);
+        context.bind(JndiLookup.CONTAINER_JNDI_RESOURCE_PATH_PREFIX + TEST_STRINGS_NAME, TEST_STRINGS_COLLECTION);
     }
 
     @After
@@ -66,4 +74,14 @@ public class JndiLookupTest {
         final String nonExistingResource = lookup.lookup("logging/non-existing-resource");
         assertNull(nonExistingResource);
     }
+
+    @Test
+    public void testNonStringLookup() throws Exception {
+        // LOG4J2-1310
+        final StrLookup lookup = new JndiLookup();
+        final String integralValue = lookup.lookup(TEST_INTEGRAL_NAME);
+        assertEquals(String.valueOf(TEST_INTEGRAL_VALUE), integralValue);
+        final String collectionValue = lookup.lookup(TEST_STRINGS_NAME);
+        assertEquals(String.valueOf(TEST_STRINGS_COLLECTION), collectionValue);
+    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c6318b63/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 61006a1..1313ac9 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -205,6 +205,9 @@
       <action issue="LOG4J2-1133" dev="mattsicker" type="add">
         Add JNDI lookup documentation.
       </action>
+      <action issue="LOG4J2-1310" dev="mattsicker" type="fix">
+        JndiLookup mindlessly casts to String and should use String.valueOf().
+      </action>
     </release>
     <release version="2.5" date="2015-12-06" description="GA Release 2.5">
       <action issue="LOG4J2-324" dev="rpopma" type="fix">