From 647495edd366bac67727a5be8e651fcca030e0aa Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 12 Feb 2009 23:46:17 +0000 Subject: [PATCH] avoid NPE in PathMatchingResourcePatternResolver when initialized with null ClassLoader --- .../springframework/core/io/DefaultResourceLoader.java | 8 +++----- .../io/support/PathMatchingResourcePatternResolver.java | 3 ++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/org.springframework.core/src/main/java/org/springframework/core/io/DefaultResourceLoader.java b/org.springframework.core/src/main/java/org/springframework/core/io/DefaultResourceLoader.java index d422c50ed19..46b5e273aa2 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/io/DefaultResourceLoader.java +++ b/org.springframework.core/src/main/java/org/springframework/core/io/DefaultResourceLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -74,15 +74,13 @@ public class DefaultResourceLoader implements ResourceLoader { } /** - * Return the ClassLoader to load class path resources with, - * or null if using the thread context class loader on actual access - * (applying to the thread that constructs the ClassPathResource object). + * Return the ClassLoader to load class path resources with. *

Will get passed to ClassPathResource's constructor for all * ClassPathResource objects created by this resource loader. * @see ClassPathResource */ public ClassLoader getClassLoader() { - return this.classLoader; + return (this.classLoader != null ? this.classLoader : ClassUtils.getDefaultClassLoader()); } diff --git a/org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java b/org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java index 0756cce85a9..23a86994427 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java +++ b/org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -198,6 +198,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol * Create a new PathMatchingResourcePatternResolver with a DefaultResourceLoader. * @param classLoader the ClassLoader to load classpath resources with, * or null for using the thread context class loader + * at the time of actual resource access * @see org.springframework.core.io.DefaultResourceLoader */ public PathMatchingResourcePatternResolver(ClassLoader classLoader) {