Skip to content

fix possible resource leaks #11624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.boot.devtools.autoconfigure;

import java.sql.Connection;
import java.sql.Statement;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -97,7 +99,11 @@ static final class NonEmbeddedInMemoryDatabaseShutdownExecutor
@Override
public void destroy() throws Exception {
if (dataSourceRequiresShutdown()) {
this.dataSource.getConnection().createStatement().execute("SHUTDOWN");
try (Connection connection = this.dataSource.getConnection()) {
try (Statement statement = connection.createStatement()) {
statement.execute("SHUTDOWN");
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,16 @@ public void writeLoaderClasses() throws IOException {
@Override
public void writeLoaderClasses(String loaderJarResourceName) throws IOException {
URL loaderJar = getClass().getClassLoader().getResource(loaderJarResourceName);
JarInputStream inputStream = new JarInputStream(
new BufferedInputStream(loaderJar.openStream()));
JarEntry entry;
while ((entry = inputStream.getNextJarEntry()) != null) {
if (entry.getName().endsWith(".class")) {
writeEntry(new JarArchiveEntry(entry),
new InputStreamEntryWriter(inputStream, false));
try (JarInputStream inputStream = new JarInputStream(
new BufferedInputStream(loaderJar.openStream()))) {
JarEntry entry;
while ((entry = inputStream.getNextJarEntry()) != null) {
if (entry.getName().endsWith(".class")) {
writeEntry(new JarArchiveEntry(entry),
new InputStreamEntryWriter(inputStream, false));
}
}
}
inputStream.close();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ public Manifest getManifest() throws IOException {
Manifest manifest = (this.manifest == null ? null : this.manifest.get());
if (manifest == null) {
if (this.type == JarFileType.NESTED_DIRECTORY) {
manifest = new JarFile(this.getRootJarFile()).getManifest();
try (JarFile rootJarFile = new JarFile(this.getRootJarFile())) {
manifest = rootJarFile.getManifest();
}
}
else {
try (InputStream inputStream = getInputStream(MANIFEST_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ private boolean hasDevtools() {
private boolean checkForDevtools() {
try {
URL[] urls = getClassPathUrls();
URLClassLoader classLoader = new URLClassLoader(urls);
return (classLoader.findResource(RESTARTER_CLASS_LOCATION) != null);
try (URLClassLoader classLoader = new URLClassLoader(urls)) {
return (classLoader.findResource(RESTARTER_CLASS_LOCATION) != null);
}
}
catch (Exception ex) {
return false;
Expand Down