Skip to content

Commit

Permalink
[groovyscripting] Prevent CNFE for scoped classes unavailable to the …
Browse files Browse the repository at this point in the history
…class loader (#17860)

Fixes the ClassNotFoundException when using Thing actions caused by #17383.
The GroovyClassLoader loads classes by name however the Thing actions classes cannot be loaded by name because they are internal classes.

Fixes #17683

Signed-off-by: Wouter Born <[email protected]>
  • Loading branch information
wborn authored Dec 7, 2024
1 parent 37d910d commit 98d2579
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ public void scopeValues(ScriptEngine scriptEngine, Map<String, Object> scopeValu
ImportCustomizer importCustomizer = new ImportCustomizer();
for (Map.Entry<String, Object> entry : scopeValues.entrySet()) {
if (entry.getValue() instanceof Class<?> clazz) {
importCustomizer.addImport(entry.getKey(), clazz.getCanonicalName());
String canonicalName = clazz.getCanonicalName();
try {
// Only add imports for classes that are available to the classloader
getClass().getClassLoader().loadClass(canonicalName);
importCustomizer.addImport(entry.getKey(), canonicalName);
logger.debug("Added import for {} as {}", entry.getKey(), canonicalName);
} catch (ClassNotFoundException e) {
logger.debug("Unable to add import for {} as {}", entry.getKey(), canonicalName, e);
}
} else {
scriptEngine.put(entry.getKey(), entry.getValue());
}
Expand Down

0 comments on commit 98d2579

Please sign in to comment.