From befd75753fb9b8c44aecaffe63f8d2cd4026b196 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 15 Sep 2005 20:17:05 +0000 Subject: [PATCH] For PR libgcj/23288: * java/net/URLClassLoader.java (definePackage): Correctly order arguments to definePackage. Look up per-entry Attributes. (getAttributeValue): New method. From-SVN: r104320 --- libjava/ChangeLog | 7 ++++ libjava/java/net/URLClassLoader.java | 60 +++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index f2ec35f1711..ad81598dee9 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,10 @@ +2005-09-15 Tom Tromey + + For PR libgcj/23288: + * java/net/URLClassLoader.java (definePackage): Correctly order + arguments to definePackage. Look up per-entry Attributes. + (getAttributeValue): New method. + 2005-09-12 Thomas Fitzsimmons PR libgcj/23762 diff --git a/libjava/java/net/URLClassLoader.java b/libjava/java/net/URLClassLoader.java index 9f7126dc540..5d48c02b296 100644 --- a/libjava/java/net/URLClassLoader.java +++ b/libjava/java/net/URLClassLoader.java @@ -940,10 +940,25 @@ public class URLClassLoader extends SecureClassLoader addURL(newUrls[i]); } + /** + * 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. * @@ -958,13 +973,36 @@ public class URLClassLoader extends SecureClassLoader 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! @@ -976,8 +1014,10 @@ public class URLClassLoader extends SecureClassLoader // 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); } /**