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 77c97e4817..9d20e04094 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 @@ -73,7 +73,12 @@ public class LaunchedURLClassLoader extends URLClassLoader { return urls[0]; } } - return super.findResource(name); + try { + return super.findResource(name); + } + catch (IllegalArgumentException e) { + return null; + } } @Override diff --git a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/LaunchedURLClassLoaderTests.java b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/LaunchedURLClassLoaderTests.java index 6a8320d3d9..a96c72d45d 100644 --- a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/LaunchedURLClassLoaderTests.java +++ b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/LaunchedURLClassLoaderTests.java @@ -21,6 +21,7 @@ import java.net.URL; import org.junit.Test; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; /** @@ -28,6 +29,19 @@ import static org.junit.Assert.assertTrue; */ public class LaunchedURLClassLoaderTests { + @Test + public void resolveResourceFromWindowsFilesystem() throws Exception { + // This path is invalid - it should return null even on Windows. + // A regular URLClassLoader will deal with it gracefully. + assertNull(getClass().getClassLoader().getResource( + "c:\\Users\\user\\bar.properties")); + LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL( + "jar:file:src/test/resources/jars/app.jar!/") }, getClass() + .getClassLoader()); + // So we should too... + assertNull(loader.getResource("c:\\Users\\user\\bar.properties")); + } + @Test public void resolveResourceFromArchive() throws Exception { LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(