mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 07:02:02 +01:00
[groovyscripting] Prevent CNFE for scoped classes unavailable to the 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 <github@maindrain.net>
This commit is contained in:
parent
37d910d318
commit
98d257982c
@ -51,7 +51,15 @@ public class GroovyScriptEngineFactory extends AbstractScriptEngineFactory {
|
||||
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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user