From 808185ab4e5f55927ec0c06a3c31549024260a2c Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 8 Nov 2016 10:35:18 +0000 Subject: [PATCH] Make LaunchedURLClassLoader Java 6 compatible again Closes gh-7334 --- .../boot/loader/LaunchedURLClassLoader.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java index 4d70a94f80..f3a3b22927 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/LaunchedURLClassLoader.java @@ -27,6 +27,7 @@ import java.util.Enumeration; import java.util.jar.JarFile; import org.springframework.boot.loader.jar.Handler; +import org.springframework.lang.UsesJava7; /** * {@link ClassLoader} used by the {@link Launcher}. @@ -38,7 +39,7 @@ import org.springframework.boot.loader.jar.Handler; public class LaunchedURLClassLoader extends URLClassLoader { static { - ClassLoader.registerAsParallelCapable(); + performParallelCapableRegistration(); } /** @@ -186,4 +187,14 @@ public class LaunchedURLClassLoader extends URLClassLoader { } } + @UsesJava7 + private static void performParallelCapableRegistration() { + try { + ClassLoader.registerAsParallelCapable(); + } + catch (NoSuchMethodError ex) { + // Running on Java 6. Continue. + } + } + }