logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carn...@apache.org
Subject svn commit: r657869 - in /logging/log4j/trunk: src/changes/changes.xml src/main/java/org/apache/log4j/spi/LocationInfo.java tests/src/java/org/apache/log4j/spi/LocationInfoTest.java
Date Mon, 19 May 2008 17:14:38 GMT
Author: carnold
Date: Mon May 19 10:14:38 2008
New Revision: 657869

URL: http://svn.apache.org/viewvc?rev=657869&view=rev
Log:
Bug 44888: LocationInfo can report wrong caller when other class names contain logger class
as substring

Modified:
    logging/log4j/trunk/src/changes/changes.xml
    logging/log4j/trunk/src/main/java/org/apache/log4j/spi/LocationInfo.java
    logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/LocationInfoTest.java

Modified: logging/log4j/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/changes/changes.xml?rev=657869&r1=657868&r2=657869&view=diff
==============================================================================
--- logging/log4j/trunk/src/changes/changes.xml (original)
+++ logging/log4j/trunk/src/changes/changes.xml Mon May 19 10:14:38 2008
@@ -38,6 +38,7 @@
        <action action="add" issue="43874">SocketHubAppender should expose actual port
in use to extending classes.</action>
        <action action="add" issue="44551">SocketHubAppender in the 1.2.16 does not
support a scroll back buffer or application property</action>
        <action action="add" issue="41156">Give log4j threads reasonable names/<action>
+       <action action="fix" issue="44888">LocationInfo can report wrong caller when
other class names contain logger class name as substring.</action>
     </release>
   
     <release version="1.2.15" date="2007-08-24" description="SyslogAppender enhancements,
NTEventLogAppender and Maven build.">

Modified: logging/log4j/trunk/src/main/java/org/apache/log4j/spi/LocationInfo.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/spi/LocationInfo.java?rev=657869&r1=657868&r2=657869&view=diff
==============================================================================
--- logging/log4j/trunk/src/main/java/org/apache/log4j/spi/LocationInfo.java (original)
+++ logging/log4j/trunk/src/main/java/org/apache/log4j/spi/LocationInfo.java Mon May 19 10:14:38
2008
@@ -128,6 +128,21 @@
       if(ibegin == -1)
 	return;
 
+      //
+      //   if the next character after the class name exists
+      //       but is not a period, see if the classname is
+      //       followed by a period earlier in the trace.
+      //       Minimizes mistakeningly matching on a class whose
+      //       name is a substring of the desired class.
+      //       See bug 44888.
+      if (ibegin + fqnOfCallingClass.length() < s.length() &&
+              s.charAt(ibegin + fqnOfCallingClass.length()) != '.') {
+          int i = s.lastIndexOf(fqnOfCallingClass + ".");
+          if (i != -1) {
+              ibegin = i;
+          }
+      }
+
 
       ibegin = s.indexOf(Layout.LINE_SEP, ibegin);
       if(ibegin == -1)

Modified: logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/LocationInfoTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/LocationInfoTest.java?rev=657869&r1=657868&r2=657869&view=diff
==============================================================================
--- logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/LocationInfoTest.java (original)
+++ logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/LocationInfoTest.java Mon May
19 10:14:38 2008
@@ -42,4 +42,44 @@
                 li.fullInfo);
     }
 
+
+    /**
+     * Class with name that is a substring of its caller.
+     */
+    private static class NameSubstring {
+        /**
+         * Construct a LocationInfo.  Location should be immediate caller of this method.
+         * @return location info.
+         */
+        public static LocationInfo getInfo() {
+            return new LocationInfo(new Throwable(), NameSubstring.class.getName());
+
+        }
+    }
+
+    /**
+     * Class whose name is contains the name of the class that obtains the LocationInfo.
+     */
+    private static class NameSubstringCaller {
+        /**
+         * Construct a locationInfo.  Location should be this location.
+         * @return location info.
+         */
+        public static LocationInfo getInfo() {
+            return NameSubstring.getInfo();
+        }
+
+    }
+
+    /**
+     * Tests creation of location info when the logger class name
+     * is a substring of one of the other classes in the stack trace.
+     * See bug 44888.
+     */
+     public void testLocationInfo() {
+         LocationInfo li = NameSubstringCaller.getInfo();
+         assertEquals(NameSubstringCaller.class.getName(), li.getClassName());
+         assertEquals("getInfo", li.getMethodName());
+     }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message