Patch: Fix line-number lookup in creating a StackTraceElement

Ranjit Mathew rmathew@hotmail.com
Wed Feb 12 20:04:00 GMT 2003


Hi,

    On Win32, in an exception stack trace the file name in a stack
trace element was not being printed properly. I could trace it to
the fact that since Win32 source file names could look like 
"G:/src/Foo.java", createStackTraceElement( ) in gnu.gcj.NameFinder
got confused while looking for the line number in an addr2line
location output like "G:/src/Foo.java:19".

The following patch proposes to remedy this by using lastIndexOf( )
instead of indexOf( ) to find the position of the colon separating
the file name from the line number.

Ranjit.


Index: ChangeLog
from  Ranjit Mathew  <rmathew@hotmail.com>

	* gnu/gcj/runtime/NameFinder.java (createStackTraceElement): Use
	lastIndexOf( ) instead of indexOf( ) to find the colon before
	the line number, because Win32 file names might contain a 
	drive letter and a colon at the start of an absolute path.

Index: gnu/gcj/runtime/NameFinder.java
===================================================================
--- gnu/gcj/runtime/NameFinder.java	2003-02-13 00:14:40.000000000 +0530
+++ gnu/gcj/runtime/NameFinder.java	2003-02-13 00:15:38.000000000 +0530
@@ -372,5 +372,5 @@
     if (fileName != null)
       {
-	int colon = file.indexOf(':');
+	int colon = file.lastIndexOf(':');
 	if (colon > 0)
 	  {



More information about the Java-patches mailing list