logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1396344 - /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
Date Tue, 09 Oct 2012 21:37:44 GMT
Author: ggregory
Date: Tue Oct  9 21:37:44 2012
New Revision: 1396344

URL: http://svn.apache.org/viewvc?rev=1396344&view=rev
Log:
Work around the regression bug in Class.getDeclaredMethods() in Oracle Java in version >
1.6.0_17: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6815786

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java?rev=1396344&r1=1396343&r2=1396344&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java
Tue Oct  9 21:37:44 2012
@@ -16,19 +16,20 @@
  */
 package org.apache.logging.log4j.core.pattern;
 
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.plugins.PluginManager;
-import org.apache.logging.log4j.core.config.plugins.PluginType;
-import org.apache.logging.log4j.status.StatusLogger;
-
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.plugins.PluginManager;
+import org.apache.logging.log4j.core.config.plugins.PluginType;
+import org.apache.logging.log4j.status.StatusLogger;
+
 /**
  * Most of the work of the {@link org.apache.logging.log4j.core.layout.PatternLayout} class
  * is delegated to the PatternParser class.
@@ -425,24 +426,27 @@ public final class PatternParser {
             return null;
         }
 
+        // Work around the regression bug in Class.getDeclaredMethods() in Oracle Java in
version > 1.6.0_17:
+        // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6815786
         Method[] methods = converterClass.getDeclaredMethods();
-        Method newInstance = null;
+        Method newInstanceMethod = null;
         for (Method method : methods) {
-            if (method.getName().equals("newInstance")) {
-                if (newInstance == null) {
-                    newInstance = method;
-                } else {
-                    LOGGER.error("Class " + converterClass + " cannot contain multiple newInstance
methods");
+            if (Modifier.isStatic(method.getModifiers()) && method.getDeclaringClass().equals(converterClass)
&&
+                    method.getName().equals("newInstance")) {
+                if (newInstanceMethod == null) {
+                    newInstanceMethod = method;
+                } else if (method.getReturnType().equals(newInstanceMethod.getReturnType()))
{
+                    LOGGER.error("Class " + converterClass + " cannot contain multiple static
newInstance methods");
                     return null;
                 }
             }
         }
-        if (newInstance == null) {
-            LOGGER.error("Class " + converterClass + " does not contain a newInstance method");
+        if (newInstanceMethod == null) {
+            LOGGER.error("Class " + converterClass + " does not contain a static newInstance
method");
             return null;
         }
 
-        Class[] parmTypes = newInstance.getParameterTypes();
+        Class[] parmTypes = newInstanceMethod.getParameterTypes();
         Object [] parms = parmTypes.length > 0 ? new Object[parmTypes.length] : null;
 
         if (parms != null) {
@@ -455,7 +459,7 @@ public final class PatternParser {
                 } else if (clazz.isAssignableFrom(Configuration.class)) {
                     parms[i] = config;
                 } else {
-                    LOGGER.error("Unknown parameter type " + clazz.getName() + " for newInstance
method of " +
+                    LOGGER.error("Unknown parameter type " + clazz.getName() + " for static
newInstance method of " +
                         converterClass.getName());
                     errors = true;
                 }
@@ -467,7 +471,7 @@ public final class PatternParser {
         }
 
         try {
-            Object newObj = newInstance.invoke(null, parms);
+            Object newObj = newInstanceMethod.invoke(null, parms);
 
             if (newObj instanceof PatternConverter) {
                 currentLiteral.delete(0, currentLiteral.length()



Mime
View raw message