Skip to content

Commit

Permalink
Fixed NPE - the unusedJarsCheck is sometimes null
Browse files Browse the repository at this point in the history
Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Oct 8, 2023
1 parent de97abe commit 00fa176
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ void closeJarFiles() {
closeJarFiles(files);
} finally {
// No need to interrupt, just cancel next executions
this.unusedJarsCheck.cancel(false);
if (this.unusedJarsCheck != null) {
this.unusedJarsCheck.cancel(false);
}
writeLock.unlock();
}
}
Expand Down Expand Up @@ -240,21 +242,21 @@ private ResourceEntry createResourceEntry(String name, File file, JarFile jarFil
try {
codeBase = file.getCanonicalFile().toURI().toURL();
} catch (IOException e) {
LOG.log(DEBUG, "Invalid file: " + file, e);
LOG.log(WARNING, "Invalid file: " + file, e);
return null;
}
final URL source;
try {
source = new URL("jar:" + codeBase + "!/" + entryPath);
} catch (MalformedURLException e) {
LOG.log(DEBUG, "Cannot create valid URL of file " + file + " and entry path " + entryPath, e);
LOG.log(WARNING, "Cannot create valid URL of file " + file + " and entry path " + entryPath, e);
return null;
}
final ResourceEntry entry = new ResourceEntry(codeBase, source);
try {
entry.manifest = jarFile.getManifest();
} catch (IOException e) {
LOG.log(DEBUG, "Failed to get manifest from " + jarFile.getName(), e);
LOG.log(WARNING, "Failed to get manifest from " + jarFile.getName(), e);
return null;
}
entry.lastModified = file.lastModified();
Expand All @@ -264,7 +266,7 @@ private ResourceEntry createResourceEntry(String name, File file, JarFile jarFil
entry.readEntryData(name, binaryStream, contentLength, jarEntry);
}
} catch (IOException e) {
LOG.log(DEBUG, "Failed to read entry data for " + name, e);
LOG.log(WARNING, "Failed to read entry data for " + name, e);
return null;
}
return entry;
Expand Down Expand Up @@ -294,7 +296,7 @@ private static void extractResource(JarFile jarFile, File loaderDir, String path
FileOutputStream os = new FileOutputStream(resourceFile)) {
FileUtils.copy(is, os, Long.MAX_VALUE);
} catch (IOException e) {
LOG.log(DEBUG, "Failed to copy entry " + jarEntry, e);
LOG.log(WARNING, "Failed to copy entry " + jarEntry, e);
}
}
}
Expand Down

0 comments on commit 00fa176

Please sign in to comment.