Skip to content

Commit 6db6f23

Browse files
committed
Quartz ResourceLoaderClassLoadHelper explicitly falls back to classpath lookup
Issue: SPR-13706
1 parent 6573e91 commit 6db6f23

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

spring-context-support/src/main/java/org/springframework/scheduling/quartz/ResourceLoaderClassLoadHelper.java

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.scheduling.quartz;
1818

19-
import java.io.FileNotFoundException;
2019
import java.io.IOException;
2120
import java.io.InputStream;
2221
import java.net.URL;
@@ -73,43 +72,50 @@ public void initialize() {
7372
}
7473

7574
@Override
76-
@SuppressWarnings("rawtypes")
77-
public Class loadClass(String name) throws ClassNotFoundException {
75+
public Class<?> loadClass(String name) throws ClassNotFoundException {
7876
return this.resourceLoader.getClassLoader().loadClass(name);
7977
}
8078

8179
@SuppressWarnings("unchecked")
8280
public <T> Class<? extends T> loadClass(String name, Class<T> clazz) throws ClassNotFoundException {
83-
return loadClass(name);
81+
return (Class<? extends T>) loadClass(name);
8482
}
8583

8684
@Override
8785
public URL getResource(String name) {
8886
Resource resource = this.resourceLoader.getResource(name);
89-
try {
90-
return resource.getURL();
91-
}
92-
catch (FileNotFoundException ex) {
93-
return null;
87+
if (resource.exists()) {
88+
try {
89+
return resource.getURL();
90+
}
91+
catch (IOException ex) {
92+
if (logger.isWarnEnabled()) {
93+
logger.warn("Could not load " + resource);
94+
}
95+
return null;
96+
}
9497
}
95-
catch (IOException ex) {
96-
logger.warn("Could not load " + resource);
97-
return null;
98+
else {
99+
return getClassLoader().getResource(name);
98100
}
99101
}
100102

101103
@Override
102104
public InputStream getResourceAsStream(String name) {
103105
Resource resource = this.resourceLoader.getResource(name);
104-
try {
105-
return resource.getInputStream();
106-
}
107-
catch (FileNotFoundException ex) {
108-
return null;
106+
if (resource.exists()) {
107+
try {
108+
return resource.getInputStream();
109+
}
110+
catch (IOException ex) {
111+
if (logger.isWarnEnabled()) {
112+
logger.warn("Could not load " + resource);
113+
}
114+
return null;
115+
}
109116
}
110-
catch (IOException ex) {
111-
logger.warn("Could not load " + resource);
112-
return null;
117+
else {
118+
return getClassLoader().getResourceAsStream(name);
113119
}
114120
}
115121

0 commit comments

Comments
 (0)