File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
main/java/com/github/mustachejava/resolver
test/java/com/github/mustachejava/resolver Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ public Reader getReader(String resourceName) {
35
35
String normalizeResourceName = URI .create (fullResourceName ).normalize ().getPath ();
36
36
37
37
URL resource = ccl .getResource (normalizeResourceName );
38
- if (resource != null )
38
+ if (resource != null ) {
39
39
if (resource .getProtocol ().equals ("jar" )) {
40
40
if (normalizeResourceName .endsWith ("/" )) {
41
41
// This is a directory
@@ -50,8 +50,10 @@ public Reader getReader(String resourceName) {
50
50
return null ;
51
51
}
52
52
}
53
- else
53
+ } else {
54
54
resource = ClasspathResolver .class .getClassLoader ().getResource (normalizeResourceName );
55
+ }
56
+
55
57
56
58
if (resource != null ) {
57
59
try {
Original file line number Diff line number Diff line change 3
3
import org .junit .Test ;
4
4
5
5
import java .io .Reader ;
6
+ import java .net .URL ;
7
+ import java .net .URLClassLoader ;
6
8
7
9
import static org .junit .Assert .assertNotNull ;
8
10
import static org .junit .Assert .assertNull ;
@@ -125,4 +127,19 @@ public void getReaderWithRootAndResourceAboveRoot() throws Exception {
125
127
assertNotNull (reader );
126
128
}
127
129
}
130
+
131
+ @ Test
132
+ public void getReaderWithoutContextClassLoader () throws Exception {
133
+ ClassLoader savedContextClassLoader = Thread .currentThread ().getContextClassLoader ();
134
+ try {
135
+ Thread .currentThread ().setContextClassLoader (new URLClassLoader (new URL []{}, null ));
136
+
137
+ ClasspathResolver underTest = new ClasspathResolver ();
138
+ try (Reader reader = underTest .getReader ("template.mustache" )) {
139
+ assertNotNull (reader );
140
+ }
141
+ } finally {
142
+ Thread .currentThread ().setContextClassLoader (savedContextClassLoader );
143
+ }
144
+ }
128
145
}
You can’t perform that action at this time.
0 commit comments