public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Patch: FYI: Fix PR 20198
@ 2006-01-17 19:57 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2006-01-17 19:57 UTC (permalink / raw)
  To: Java Patch List

I'm checking this in on the trunk and the 4.1 branch.
I'll put something similar in Classpath shortly.

This fixes PR 20198 by ensuring that we use absolute paths when
fetching resources via a file: URL.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	PR classpath/20198:
	* java/net/URLClassLoader.java (FileURLLoader): Added argument.
	(JarURLLoader): Likewise.
	(addURLImpl): Canonicalize file URLs.

Index: java/net/URLClassLoader.java
===================================================================
--- java/net/URLClassLoader.java	(revision 109497)
+++ java/net/URLClassLoader.java	(working copy)
@@ -1,5 +1,5 @@
 /* URLClassLoader.java --  ClassLoader that loads classes from one or more URLs
-   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
    Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
@@ -305,9 +305,10 @@
 
     Vector classPath;	// The "Class-Path" attribute of this Jar's manifest
 
-    public JarURLLoader(URLClassLoader classloader, URL baseURL)
+    public JarURLLoader(URLClassLoader classloader, URL baseURL,
+			URL absoluteUrl)
     {
-      super(classloader, baseURL);
+      super(classloader, baseURL, absoluteUrl);
 
       // Cache url prefix for all resources in this jar url.
       String external = baseURL.toExternalForm();
@@ -601,10 +602,10 @@
   {
     File dir; //the file for this file url
 
-    FileURLLoader(URLClassLoader classloader, URL url)
+    FileURLLoader(URLClassLoader classloader, URL url, URL absoluteUrl)
     {
-      super(classloader, url);
-      dir = new File(baseURL.getFile());
+      super(classloader, url, absoluteUrl);
+      dir = new File(absoluteUrl.getFile());
     }
 
     /** get resource with the name "name" in the file url */
@@ -885,13 +886,44 @@
             String file = newUrl.getFile();
             String protocol = newUrl.getProtocol();
 
+	    // If we have a file: URL, we want to make it absolute
+	    // here, before we decide whether it is really a jar.
+	    URL absoluteURL;
+	    if ("file".equals (protocol))
+	      {
+		File dir = new File(file);
+		URL absUrl;
+		try
+		  {
+		    absoluteURL = dir.getCanonicalFile().toURL();
+		  }
+		catch (IOException ignore)
+		  {
+		    try
+		      {
+			absoluteURL = dir.getAbsoluteFile().toURL();
+		      }
+		    catch (MalformedURLException _)
+		      {
+			// This really should not happen.
+			absoluteURL = newUrl;
+		      }
+		  }
+	      }
+	    else
+	      {
+		// This doesn't hurt, and it simplifies the logic a
+		// little.
+		absoluteURL = newUrl;
+	      }
+
             // Check that it is not a directory
 	    if ("gcjlib".equals(protocol))
 	      loader = new SoURLLoader(this, newUrl);
 	    else if (! (file.endsWith("/") || file.endsWith(File.separator)))
-              loader = new JarURLLoader(this, newUrl);
+              loader = new JarURLLoader(this, newUrl, absoluteURL);
             else if ("file".equals(protocol))
-              loader = new FileURLLoader(this, newUrl);
+	      loader = new FileURLLoader(this, newUrl, absoluteURL);
 	    else if ("core".equals(protocol))
 	      loader = new CoreURLLoader(this, newUrl);
             else

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-01-17 19:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-17 19:57 Patch: FYI: Fix PR 20198 Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).