From 43e531129a65277fe0e775f3b80b8714d68d237c Mon Sep 17 00:00:00 2001 From: Zbyszek Date: Tue, 24 May 2022 22:49:45 +0200 Subject: [PATCH] fix for issue NullPointerException in ClassList.loadClassList when context class loader is unavailable in current thread (#401) --- src/main/java/jep/ClassList.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/jep/ClassList.java b/src/main/java/jep/ClassList.java index 501a4a8e..89454578 100644 --- a/src/main/java/jep/ClassList.java +++ b/src/main/java/jep/ClassList.java @@ -256,10 +256,17 @@ private void loadClassList() throws JepException { * different ClassLoader than classes (e.g. tomcat), while the Jep.class * ClassLoader is useful if running inside an OSGi container as a Bundle * (e.g. eclipse). + * If there is no context ClassLoader then system ClassLoader will be tried. */ + boolean hasContextClassloader = Thread.currentThread() != null + && Thread.currentThread().getContextClassLoader() != null; + ClassLoader parentClassLoader = hasContextClassloader + ? Thread.currentThread().getContextClassLoader() + : ClassLoader.getSystemClassLoader(); ClassLoader[] classloadersToTry = new ClassLoader[] { - Thread.currentThread().getContextClassLoader(), - Jep.class.getClassLoader() }; + parentClassLoader, + Jep.class.getClassLoader() + }; String rsc = "jep/classlist_"; if (version.startsWith("1.8")) { rsc += "8";