Skip to content

Commit

Permalink
Refine PropertiesLauncher close logic
Browse files Browse the repository at this point in the history
Further attempt to fix Windows file issues.

See gh-21575
  • Loading branch information
philwebb committed Jun 11, 2020
1 parent 1e7da4d commit 2a37b2e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.jar.Manifest;
Expand Down Expand Up @@ -531,7 +529,7 @@ private class ClassPathArchives implements Iterable<Archive> {

private final List<Archive> classPathArchives;

private final Map<File, JarFileArchive> jarFileArchives = new LinkedHashMap<>();
private final List<JarFileArchive> jarFileArchives = new ArrayList<>();

ClassPathArchives() throws Exception {
this.classPathArchives = new ArrayList<>();
Expand Down Expand Up @@ -666,11 +664,8 @@ private List<Archive> asList(Iterator<Archive> iterator) {
}

private JarFileArchive getJarFileArchive(File file) throws IOException {
JarFileArchive archive = this.jarFileArchives.get(file);
if (archive == null) {
archive = new JarFileArchive(file);
this.jarFileArchives.put(file, archive);
}
JarFileArchive archive = new JarFileArchive(file);
this.jarFileArchives.add(archive);
return archive;
}

Expand All @@ -680,7 +675,7 @@ public Iterator<Archive> iterator() {
}

void close() throws IOException {
for (JarFileArchive archive : this.jarFileArchives.values()) {
for (JarFileArchive archive : this.jarFileArchives) {
archive.close();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ void loadResourceFromJarFile() throws Exception {
this.launcher.launch(new String[0]);
}
catch (Exception ex) {
// Expected ClassNotFoundException
LaunchedURLClassLoader classLoader = (LaunchedURLClassLoader) Thread.currentThread()
.getContextClassLoader();
classLoader.close();
}
URL resource = new URL("jar:" + jarFile.toURI() + "!/nested.jar!/3.dat");
byte[] bytes = FileCopyUtils.copyToByteArray(resource.openStream());
Expand Down

0 comments on commit 2a37b2e

Please sign in to comment.