From accb8519fd923f07dd79b0cc41db179d416c64e6 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Mon, 27 Jul 2015 14:16:09 +0200 Subject: [PATCH] Polish WebJarsResourceResolver Fix a potential NPE when trying to resolve non-existing webjars resources in the resolver chain. --- .../web/servlet/resource/WebJarsResourceResolver.java | 4 +++- .../web/servlet/resource/WebJarsResourceResolverTests.java | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/WebJarsResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/WebJarsResourceResolver.java index 98c8341930..f487994f44 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/WebJarsResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/WebJarsResourceResolver.java @@ -75,7 +75,9 @@ public class WebJarsResourceResolver extends AbstractResourceResolver { String path = chain.resolveUrlPath(resourceUrlPath, locations); if (path == null) { String webJarResourcePath = findWebJarResourcePath(resourceUrlPath); - return chain.resolveUrlPath(webJarResourcePath, locations); + if(webJarResourcePath != null) { + return chain.resolveUrlPath(webJarResourcePath, locations); + } } return path; } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/WebJarsResourceResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/WebJarsResourceResolverTests.java index f80183304e..4fddeb734e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/WebJarsResourceResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/WebJarsResourceResolverTests.java @@ -107,6 +107,7 @@ public class WebJarsResourceResolverTests { assertNull(actual); verify(this.chain, times(1)).resolveUrlPath(file, this.locations); + verify(this.chain, never()).resolveUrlPath(null, this.locations); } @Test