mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +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> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
aee5cc9c25
commit
d7ca3da98c
@ -51,7 +51,15 @@ public class GroovyScriptEngineFactory extends AbstractScriptEngineFactory {
|
|||||||
ImportCustomizer importCustomizer = new ImportCustomizer();
|
ImportCustomizer importCustomizer = new ImportCustomizer();
|
||||||
for (Map.Entry<String, Object> entry : scopeValues.entrySet()) {
|
for (Map.Entry<String, Object> entry : scopeValues.entrySet()) {
|
||||||
if (entry.getValue() instanceof Class<?> clazz) {
|
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 {
|
} else {
|
||||||
scriptEngine.put(entry.getKey(), entry.getValue());
|
scriptEngine.put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user