From 1beee5700c9a2e9cd8a81fdfcb95b2e2a7e24af2 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 2 Jun 2021 12:21:56 -0700 Subject: [PATCH] Don't close early when SecurityManager present Update `JarFile` and `JarFileWrapper` classes so that they no longer close the `JarFile` early if a `SecurityManager` is in use. Prior to this commit, the closed `JarFile` would cause (an ultimately swallowed) NPE in `ZipFile` which manifested itself as a `ClassNotFoundException` when starting the app. Closes gh-25538 --- .../springframework/boot/loader/jar/JarFile.java | 16 ++++++++++++---- .../boot/loader/jar/JarFileWrapper.java | 6 ++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java index 76867cbe3d..f35b48843b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -126,7 +126,9 @@ public class JarFile extends AbstractJarFile implements Iterable manifestSupplier) throws IOException { super(rootFile.getFile()); - super.close(); + if (System.getSecurityManager() == null) { + super.close(); + } this.rootFile = rootFile; this.pathFromRoot = pathFromRoot; CentralDirectoryParser parser = new CentralDirectoryParser(); @@ -137,7 +139,12 @@ public class JarFile extends AbstractJarFile implements Iterable { @@ -337,10 +344,11 @@ public class JarFile extends AbstractJarFile implements Iterable