This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] libjava: java.net.URI.relativize method results inconsistent with other Java VMs


Howdy, 

The full details about the two problems found in the libjava
java.net.URI.relativize method are described in the following bug
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34369 along with a provided
java based testcase and comparisons of results obtained with the same
testcase executed under three other Java VMs from Sun and IBM.

Basically, I made some minor changes to the method to improve the path
prefix checking over the simpler string matching that was producing some
false positives in some cases. 

One change fixed a problem where a different path containing a URI with
a path that contained the same starting characters as another URI path.
For example, "file:/home/eclipse/runtime-New_configuration/simple" was
being incorrectly considered as a prefix of
"file:/home/eclipse/runtime-New_configuration/simple_spu/simple_spu.c".

The second change involved removing a leading '/' from the returned
relative path to make it consistent with results from other Java VMs.

This patch corrects two issues found in URI.relativize() method in
libjava/classpath/java/net/URI.java. It applies from gcc 4.1.2 through latest
trunk:

* does stricter check for a path match while still using String.startsWith()
* excludes leading '/' if necessary for relative path fragment being returned

-- 
Luciano Chavez <lnx1138@us.ibm.com>
IBM
Index: URI.java
===================================================================
--- URI.java	(revision 130639)
+++ URI.java	(working copy)
@@ -968,12 +968,19 @@
       return uri;
     if (rawAuthority != null && !(rawAuthority.equals(uri.getRawAuthority())))
       return uri;
-    if (!(uri.getRawPath().startsWith(rawPath)))
-      return uri;
+    String basePath = new String(rawPath);
+    if (!(uri.getRawPath().equals(rawPath)))
+      {
+        if (!(rawPath.endsWith("/")))
+          basePath = rawPath.concat("/");
+
+        if (!(uri.getRawPath().startsWith(basePath)))
+          return uri;
+      }
     try
       {
 	return new URI(null, null, 
-		       uri.getRawPath().substring(rawPath.length()),
+		       uri.getRawPath().substring(basePath.length()),
 		       uri.getRawQuery(), uri.getRawFragment());
       }
     catch (URISyntaxException e)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]