Early getJarFile() call for consistent jar file existence check
See gh-34796
This commit is contained in:
parent
0252e39409
commit
253f321e8b
|
@ -29,6 +29,7 @@ import java.nio.channels.ReadableByteChannel;
|
||||||
import java.nio.file.NoSuchFileException;
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
import org.springframework.util.ResourceUtils;
|
import org.springframework.util.ResourceUtils;
|
||||||
|
|
||||||
|
@ -44,6 +45,7 @@ import org.springframework.util.ResourceUtils;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractFileResolvingResource extends AbstractResource {
|
public abstract class AbstractFileResolvingResource extends AbstractResource {
|
||||||
|
|
||||||
|
@SuppressWarnings("try")
|
||||||
@Override
|
@Override
|
||||||
public boolean exists() {
|
public boolean exists() {
|
||||||
try {
|
try {
|
||||||
|
@ -86,15 +88,10 @@ public abstract class AbstractFileResolvingResource extends AbstractResource {
|
||||||
if (con instanceof JarURLConnection jarCon) {
|
if (con instanceof JarURLConnection jarCon) {
|
||||||
// For JarURLConnection, do not check content-length but rather the
|
// For JarURLConnection, do not check content-length but rather the
|
||||||
// existence of the entry (or the jar root in case of no entryName).
|
// existence of the entry (or the jar root in case of no entryName).
|
||||||
try {
|
// getJarFile() called for enforced presence check of the jar file,
|
||||||
if (jarCon.getEntryName() == null) {
|
// throwing a NoSuchFileException otherwise (turned to false below).
|
||||||
// Jar root: check for the existence of any actual jar entries.
|
try (JarFile jarFile = jarCon.getJarFile()) {
|
||||||
return jarCon.getJarFile().entries().hasMoreElements();
|
return (jarCon.getEntryName() == null || jarCon.getJarEntry() != null);
|
||||||
}
|
|
||||||
return (jarCon.getJarEntry() != null);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
jarCon.getJarFile().close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (con.getContentLengthLong() > 0) {
|
else if (con.getContentLengthLong() > 0) {
|
||||||
|
|
Loading…
Reference in New Issue