[PATCH] Fix URLStreamHandler.parseURL for Win32

Mohan Embar gnustuff@thisiscool.com
Mon Jun 28 08:28:00 GMT 2004


Hi People,

The change to URLStreamHandler.parseURL of this patch:

	2004-04-22  Jeroen Frijters <jeroen@sumatra.nl>
	
	* java/net/URLStreamHandler.java
	(parseURL): Convert the file path to using '/' instead of native
	file separator.

...causes a StringIndexOutOfBoundsException for the attached
testcase on MinGW on the mainline because of this block of code:

	int lastSlash = file.lastIndexOf('/');

	file =
	  file.substring(0, lastSlash) + '/' + spec.substring(start, end);

...because file = ".\" on Win32. The solution seems to be to
canonicalize both the file portion of the URL and not just the spec
if the file: protocol is used.

Tested with the attached testcase on i686-pc-mingw32 and i686-pc-linux-gnu.
Additionally tested against the libjava testsuite and Mauve for i686-pc-linux-gnu.

(Is this the right list or do I need to send these sort of things
to the Classpath folks too?)

-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/

ChangeLog
2004-06-26  Mohan Embar  <gnustuff@thisiscool.com>

	* java/net/URLStreamHandler.java (parseURL): Canonicalize
	file portion of URL in addition to spec for file: protocol.

Index: java/net/URLStreamHandler.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLStreamHandler.java,v
retrieving revision 1.29
diff -u -2 -r1.29 URLStreamHandler.java
--- java/net/URLStreamHandler.java	5 May 2004 08:51:04 -0000	1.29
+++ java/net/URLStreamHandler.java	27 Jun 2004 19:17:14 -0000
@@ -132,6 +132,10 @@
     
     // On Windows we need to change \ to / for file URLs
-    if (url.getProtocol().equals("file"))
-      spec = spec.replace(File.separatorChar, '/');
+    char separator = File.separatorChar;
+    if (url.getProtocol().equals("file") && separator != '/')
+      {
+	file = file.replace(separator, '/');
+	spec = spec.replace(separator, '/');
+      }
 
     if (spec.regionMatches(start, "//", 0, 2))
@@ -217,5 +221,5 @@
 		boolean endsWithSlash = file.charAt(file.length() - 1) == '/';
 		file = new File(file).getCanonicalPath();
-		file = file.replace(File.separatorChar, '/');
+		file = file.replace(separator, '/');
 		if (endsWithSlash && file.charAt(file.length() - 1) != '/')
 		  file += '/';

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ResourceAsStream.tar.bz2
Type: application/bzip2
Size: 601 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20040628/a95ff692/attachment.bin>


More information about the Java-patches mailing list