classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] Patch: FYI: fix PR 20198


From: Tom Tromey
Subject: [cp-patches] Patch: FYI: fix PR 20198
Date: 17 Jan 2006 17:14:20 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

I'm checking this in.

This fixes PR 20198.  We want CodeSource objects created by
URLClassLoader for classes loaded via file: URLs to use the absolute
directory.  Some programs rely on this.

Tom

Index: ChangeLog
from  Tom Tromey  <address@hidden>

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

Index: java/net/URLClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/URLClassLoader.java,v
retrieving revision 1.43
diff -u -r1.43 URLClassLoader.java
--- java/net/URLClassLoader.java 17 Nov 2005 15:26:28 -0000 1.43
+++ java/net/URLClassLoader.java 18 Jan 2006 00:17:28 -0000
@@ -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.
@@ -292,9 +292,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();
@@ -526,10 +527,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 */
@@ -723,11 +724,42 @@
             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 (! (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
               loader = new RemoteURLLoader(this, newUrl);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]