classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] Patch: FYI: fixes for URLClassLoader manifest handling


From: Tom Tromey
Subject: [cp-patches] Patch: FYI: fixes for URLClassLoader manifest handling
Date: 09 Sep 2005 15:36:06 -0600

I'm checking this in.

This fixes some problems I noticed in URLClassLoader manifest
handling.  In particular we weren't looking at per-package entries
in definePackage, and we were passing arguments to definePackage in
the wrong order.

This is part of PR 23288, but not all of it.

Tom

Index: ChangeLog
from  Tom Tromey  <address@hidden>

        For PR libgcj/23288:
        * java/net/URLClassLoader.java (definePackage): Correctly order
        arguments to definePackage.  Look up per-entry Attributes.
        (getAttributeValue): New method.

Index: java/net/URLClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/URLClassLoader.java,v
retrieving revision 1.35
diff -u -r1.35 URLClassLoader.java
--- java/net/URLClassLoader.java 9 Sep 2005 12:59:54 -0000 1.35
+++ java/net/URLClassLoader.java 9 Sep 2005 21:10:46 -0000
@@ -758,30 +758,68 @@
   }
 
   /**
+   * Look in both Attributes for a given value.  The first Attributes
+   * object, if not null, has precedence.
+   */
+  private String getAttributeValue(Attributes.Name name, Attributes first,
+                                  Attributes second)
+  {
+    String result = null;
+    if (first != null)
+      result = first.getValue(name);
+    if (result == null)
+      result = second.getValue(name);
+    return result;
+  }
+
+  /**
    * Defines a Package based on the given name and the supplied manifest
-   * information. The manifest indicates the tile, version and
-   * vendor information of the specification and implementation and wheter the
+   * information. The manifest indicates the title, version and
+   * vendor information of the specification and implementation and whether the
    * package is sealed. If the Manifest indicates that the package is sealed
    * then the Package will be sealed with respect to the supplied URL.
    *
+   * @exception IllegalArgumentException If this package name already exists
+   * in this class loader
    * @param name The name of the package
    * @param manifest The manifest describing the specification,
    * implementation and sealing details of the package
    * @param url the code source url to seal the package
-   * @exception IllegalArgumentException If this package name already exists
-   * in this class loader
    * @return the defined Package
    */
   protected Package definePackage(String name, Manifest manifest, URL url)
     throws IllegalArgumentException
   {
+    // Compute the name of the package as it may appear in the
+    // Manifest.
+    StringBuffer xform = new StringBuffer(name);
+    for (int i = xform.length () - 1; i >= 0; --i)
+      if (xform.charAt(i) == '.')
+       xform.setCharAt(i, '/');
+    xform.append('/');
+    String xformName = xform.toString();
+
+    Attributes entryAttr = manifest.getAttributes(xformName);
     Attributes attr = manifest.getMainAttributes();
-    String specTitle = attr.getValue(Attributes.Name.SPECIFICATION_TITLE);
-    String specVersion = attr.getValue(Attributes.Name.SPECIFICATION_VERSION);
-    String specVendor = attr.getValue(Attributes.Name.SPECIFICATION_VENDOR);
-    String implTitle = attr.getValue(Attributes.Name.IMPLEMENTATION_TITLE);
-    String implVersion = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
-    String implVendor = attr.getValue(Attributes.Name.IMPLEMENTATION_VENDOR);
+
+    String specTitle
+      = getAttributeValue(Attributes.Name.SPECIFICATION_TITLE,
+                         entryAttr, attr);
+    String specVersion
+      = getAttributeValue(Attributes.Name.SPECIFICATION_VERSION,
+                         entryAttr, attr);
+    String specVendor
+      = getAttributeValue(Attributes.Name.SPECIFICATION_VENDOR,
+                         entryAttr, attr);
+    String implTitle
+      = getAttributeValue(Attributes.Name.IMPLEMENTATION_TITLE,
+                         entryAttr, attr);
+    String implVersion
+      = getAttributeValue(Attributes.Name.IMPLEMENTATION_VERSION,
+                         entryAttr, attr);
+    String implVendor
+      = getAttributeValue(Attributes.Name.IMPLEMENTATION_VENDOR,
+                         entryAttr, attr);
 
     // Look if the Manifest indicates that this package is sealed
     // XXX - most likely not completely correct!
@@ -793,8 +831,10 @@
       // make sure that the URL is null so the package is not sealed
       url = null;
 
-    return definePackage(name, specTitle, specVersion, specVendor, implTitle,
-                         implVersion, implVendor, url);
+    return definePackage(name,
+                        specTitle, specVendor, specVersion,
+                        implTitle, implVendor, implVersion,
+                        url);
   }
 
   /**




reply via email to

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