PR java/14070: gij and -jar argument should set the manifest Class-path recursively

Andrew Haley aph@redhat.com
Tue Nov 2 17:53:00 GMT 2004


OK, this is the new, improved, low-fat version of the patch.

urls was a Vector, and I've changed it to a LinkedHashSet.  When we
add a URL, we first check that we haven't added it already, and this
prevents the loader from looping.

Andrew.


2004-11-02  Andrew Haley  <aph@redhat.com>

	* java/net/URLClassLoader.java (urls): Now a LinkedHashSet.
	(JarURLLoader.classPath): New field.
	(JarURLLoader.JarURLLoader): Read mainfest to parse "Class-Path"
	attribute and add URLs for each entry.
	(addURLImpl): Don't add a URL if it's already in the list.
	(definePackage, findURLResource, findResources): Use
	urlinfos.size(), not urls.size().
	
Index: java/net/URLClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLClassLoader.java,v
retrieving revision 1.16.18.4
diff -p -2 -c -r1.16.18.4 URLClassLoader.java
*** java/net/URLClassLoader.java	12 Oct 2004 14:53:07 -0000	1.16.18.4
--- java/net/URLClassLoader.java	2 Nov 2004 17:46:19 -0000
*************** import java.security.cert.Certificate;
*** 54,57 ****
--- 54,59 ----
  import java.util.Enumeration;
  import java.util.HashMap;
+ import java.util.LinkedHashSet;
+ import java.util.StringTokenizer;
  import java.util.Vector;
  import java.util.jar.Attributes;
*************** public class URLClassLoader extends Secu
*** 141,150 ****
  
    /** Locations to load classes from */
!   private final Vector urls = new Vector();
  
    /**
!    * Store pre-parsed information for each url into this vector
!    * each element is a URL loader, corresponding to the URL of
!    * the same index in "urls"
     */
    private final Vector urlinfos = new Vector();
--- 143,152 ----
  
    /** Locations to load classes from */
!   private final LinkedHashSet urls = new LinkedHashSet();
  
    /**
!    * Store pre-parsed information for each url into this vector: each
!    * element is a URL loader, corresponding to the URL at the same
!    * position in "urls"
     */
    private final Vector urlinfos = new Vector();
*************** public class URLClassLoader extends Secu
*** 295,298 ****
--- 297,302 ----
      final URL baseJarURL; // Base jar: url for all resources loaded from jar
  
+     String classPath;	// The "Class-Path" attribute of this Jar's manifest
+ 
      SoURLLoader soURLLoader;
  
*************** public class URLClassLoader extends Secu
*** 310,313 ****
--- 314,318 ----
  
        this.soURLLoader = null;
+       this.classPath = null;
        URL baseJarURL = null;
        JarFile jarfile = null;
*************** public class URLClassLoader extends Secu
*** 338,342 ****
  		    }
  		}
! 	    }
  	}
        catch (IOException ioe)
--- 343,373 ----
  		    }
  		}
! 
! 	      Manifest manifest;
! 	      Attributes attributes;
! 
! 	      if ((manifest = jarfile.getManifest()) != null
! 		  && (attributes = manifest.getMainAttributes()) != null
! 		  && (this.classPath = attributes.getValue(Attributes.Name.CLASS_PATH)) != null)
! 		{
! 		  StringTokenizer st
! 		    = new StringTokenizer (classPath,
! 					   System.getProperty ("path.separator", ":"));
!       
! 		  while (st.hasMoreElements ()) 
! 		    {  
! 		      String e = st.nextToken ();
! 		      try
! 			{
! 			  URL url = new URL(baseURL, e);
! 			  classloader.addURL(url);
! 			} 
! 		      catch (java.net.MalformedURLException xx)
! 			{
! 			  // Give up
! 			}
! 		    }
! 		}
!  	    }
  	}
        catch (IOException ioe)
*************** public class URLClassLoader extends Secu
*** 789,792 ****
--- 820,828 ----
  	  return; // Silently ignore...
  
+ 	if (urls.contains(newUrl))
+ 	  return;
+ 
+ 	urls.add(newUrl);
+ 
  	// Check global cache to see if there're already url loader
  	// for this url.
*************** public class URLClassLoader extends Secu
*** 806,814 ****
  	      loader = new RemoteURLLoader(this, newUrl);
  
! 	    // Cache it.
! 	    urlloaders.put(newUrl, loader);
  	  }
  
- 	urls.add(newUrl);
  	urlinfos.add(loader);
        }
--- 842,849 ----
  	      loader = new RemoteURLLoader(this, newUrl);
  
!             // Cache it.
!             urlloaders.put(newUrl, loader);
  	  }
  
  	urlinfos.add(loader);
        }
*************** public class URLClassLoader extends Secu
*** 879,883 ****
      // Just try to find the resource by the (almost) same name
      String resourceName = className.replace('.', '/') + ".class";
!     int max = urls.size();
      Resource resource = null;
      for (int i = 0; i < max && resource == null; i++)
--- 914,918 ----
      // Just try to find the resource by the (almost) same name
      String resourceName = className.replace('.', '/') + ".class";
!     int max = urlinfos.size();
      Resource resource = null;
      for (int i = 0; i < max && resource == null; i++)
*************** public class URLClassLoader extends Secu
*** 988,992 ****
    private Resource findURLResource(String resourceName)
    {
!     int max = urls.size();
      for (int i = 0; i < max; i++)
        {
--- 1023,1027 ----
    private Resource findURLResource(String resourceName)
    {
!     int max = urlinfos.size();
      for (int i = 0; i < max; i++)
        {
*************** public class URLClassLoader extends Secu
*** 1059,1063 ****
    {
      Vector resources = new Vector();
!     int max = urls.size();
      for (int i = 0; i < max; i++)
        {
--- 1094,1098 ----
    {
      Vector resources = new Vector();
!     int max = urlinfos.size();
      for (int i = 0; i < max; i++)
        {



More information about the Java-patches mailing list