Backport "Attempt to prevent JarFiles from being left open"

Update `JarFile` so that `super.close()` is called early so that the
file is not left open. Since we re-implement `JarFile` methods to work
directly on the underlying `RandomAccessDataFile`, it should be safe
to close immediately.

Closes gh-21177
This commit is contained in:
Phillip Webb
2020-04-27 19:03:52 -07:00
parent e2705b2cfd
commit 50e9674631
2 changed files with 13 additions and 4 deletions

View File

@@ -20,7 +20,6 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.URL;
import java.util.zip.ZipFile;
import org.junit.Before;
import org.junit.Rule;
@@ -29,7 +28,6 @@ import org.junit.rules.TemporaryFolder;
import org.springframework.boot.loader.TestJarCreator;
import org.springframework.boot.loader.jar.JarURLConnection.JarEntryName;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -201,7 +199,7 @@ public class JarURLConnectionTests {
JarURLConnection connection = JarURLConnection.get(url, this.jarFile);
JarFile connectionJarFile = connection.getJarFile();
connectionJarFile.close();
assertThat((Boolean) ReflectionTestUtils.getField(this.jarFile, ZipFile.class, "closeRequested")).isFalse();
assertThat(this.jarFile.isClosed()).isFalse();
}
private String getRelativePath() {