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) {
3535 String normalizeResourceName = URI .create (fullResourceName ).normalize ().getPath ();
3636
3737 URL resource = ccl .getResource (normalizeResourceName );
38- if (resource != null )
38+ if (resource != null ) {
3939 if (resource .getProtocol ().equals ("jar" )) {
4040 if (normalizeResourceName .endsWith ("/" )) {
4141 // This is a directory
@@ -50,8 +50,10 @@ public Reader getReader(String resourceName) {
5050 return null ;
5151 }
5252 }
53- else
53+ } else {
5454 resource = ClasspathResolver .class .getClassLoader ().getResource (normalizeResourceName );
55+ }
56+
5557
5658 if (resource != null ) {
5759 try {
Original file line number Diff line number Diff line change 33import org .junit .Test ;
44
55import java .io .Reader ;
6+ import java .net .URL ;
7+ import java .net .URLClassLoader ;
68
79import static org .junit .Assert .assertNotNull ;
810import static org .junit .Assert .assertNull ;
@@ -125,4 +127,19 @@ public void getReaderWithRootAndResourceAboveRoot() throws Exception {
125127 assertNotNull (reader );
126128 }
127129 }
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+ }
128145}
You can’t perform that action at this time.
0 commit comments