Permalink
Browse files

Do not provide a package definition if the package entry is non-exist…

…ent; verify JARs on load; make sure whole class body has been read before getting code signers
  • Loading branch information...
1 parent 593b89a commit ef6acf8643fce457ac4f469573fb729f63945bd1 @dmlloyd committed Nov 22, 2011
@@ -43,6 +43,9 @@ protected static PackageSpec getPackageSpec(final String name, final Manifest ma
final Attributes mainAttribute = manifest.getMainAttributes();
final String path = name.replace('.', '/').concat("/");
final Attributes entryAttribute = manifest.getAttributes(path);
+ if (entryAttribute == null || entryAttribute.isEmpty()) {
+ return null;
+ }
spec.setSpecTitle(getDefinedAttribute(Attributes.Name.SPECIFICATION_TITLE, entryAttribute, mainAttribute));
spec.setSpecVersion(getDefinedAttribute(Attributes.Name.SPECIFICATION_VERSION, entryAttribute, mainAttribute));
spec.setSpecVendor(getDefinedAttribute(Attributes.Name.SPECIFICATION_VENDOR, entryAttribute, mainAttribute));
@@ -121,7 +121,7 @@ private void addClassPath(final ModuleSpec.Builder builder, final String classPa
}
if (root.isFile()) {
try {
- builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(ResourceLoaders.createJarResourceLoader(root.getParent(), new JarFile(root))));
+ builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(ResourceLoaders.createJarResourceLoader(root.getParent(), new JarFile(root, true))));
} catch (Exception e) {
Module.log.trace(e, "Resource %s does not appear to be a valid JAR. Loaded as file resource.", root);
builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(ResourceLoaders.createFileResourceLoader(entry, root)));
@@ -90,7 +90,6 @@ public ClassSpec getClassSpec(final String fileName) throws IOException {
// no such entry
return null;
}
- spec.setCodeSource(new CodeSource(rootUrl, entry.getCodeSigners()));
final long size = entry.getSize();
final InputStream is = jarFile.getInputStream(entry);
try {
@@ -106,6 +105,7 @@ public ClassSpec getClassSpec(final String fileName) throws IOException {
baos.close();
is.close();
spec.setBytes(baos.toByteArray());
+ spec.setCodeSource(new CodeSource(rootUrl, entry.getCodeSigners()));
return spec;
} else if (size <= (long) Integer.MAX_VALUE) {
final int castSize = (int) size;
@@ -117,6 +117,7 @@ public ClassSpec getClassSpec(final String fileName) throws IOException {
// done
is.close();
spec.setBytes(bytes);
+ spec.setCodeSource(new CodeSource(rootUrl, entry.getCodeSigners()));
return spec;
} else {
throw new IOException("Resource is too large to be a valid class file");
@@ -78,7 +78,7 @@ public String toString() {
protected ModuleSpec findModule(final ModuleIdentifier identifier) throws ModuleLoadException {
if (identifier.equals(myIdentifier)) {
// special root JAR module
- Manifest manifest = null;
+ Manifest manifest;
try {
manifest = jarFile.getManifest();
} catch (IOException e) {
@@ -203,7 +203,8 @@ public ResourceLoader createResourceLoader(final String rootPath, final String l
if (file.isDirectory()) {
return new FileResourceLoader(loaderName, file);
} else {
- return new JarFileResourceLoader(loaderName, new JarFile(file));
+ final JarFile jarFile = new JarFile(file, true);
+ return new JarFileResourceLoader(loaderName, jarFile);
}
}
}, root.getPath(), fis, moduleInfoFile.getPath(), moduleIdentifier);
@@ -119,13 +119,6 @@ public void testGetPackageSpec() throws Exception {
@Test
public void testMissingPackageSpec() throws Exception {
PackageSpec spec = loader.getPackageSpec("org.jboss.modules.bogus");
- assertNotNull(spec);
-
- assertEquals("MODULES-89", spec.getSpecTitle());
- assertNull(spec.getSpecVersion());
- assertNull(spec.getSpecVendor());
- assertNull(spec.getImplTitle());
- assertNull(spec.getImplVersion());
- assertNull(spec.getImplVendor());
+ assertNull(spec);
}
}
@@ -53,7 +53,7 @@ protected ResourceLoader createLoader(final PathFilter exportFilter) throws Exce
outputFile.getParentFile().mkdirs();
buildJar(fileResourceRoot, outputFile);
// Create the jar file and resource loader
- jarFile = new JarFile(outputFile);
+ jarFile = new JarFile(outputFile, true);
return new JarFileResourceLoader("test-root", jarFile);
}

0 comments on commit ef6acf8

Please sign in to comment.