From 7428bc6859896fe722298cc0dd36c4d7664f97de Mon Sep 17 00:00:00 2001 From: Arne Seime Date: Tue, 1 Nov 2022 20:38:51 +0100 Subject: [PATCH] Fix buffer being read twice and breaking classloading --- .../jrule/internal/handler/JRuleHandler.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleHandler.java b/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleHandler.java index c2fe7c30..7eff5e07 100644 --- a/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleHandler.java +++ b/src/main/java/org/openhab/automation/jrule/internal/handler/JRuleHandler.java @@ -508,19 +508,21 @@ public Class loadClass(String name) throws ClassNotFoundException { try { for (URL url : getURLs()) { if (url.getProtocol().equals("file")) { - FileInputStream is = new FileInputStream( - url.getFile() + "/" + name.replaceAll("\\.", "/") + JRuleConstants.CLASS_FILE_TYPE); - if (is != null) { - byte[] buf = is.readAllBytes(); - is.close(); - return defineClass(name, is.readAllBytes(), 0, buf.length); + File classFile = new File(url.getPath(), + name.replaceAll("\\.", "/") + JRuleConstants.CLASS_FILE_TYPE); + if (classFile.exists()) { + FileInputStream is = new FileInputStream(classFile); + if (is != null) { + byte[] buf = is.readAllBytes(); + is.close(); + return defineClass(name, buf, 0, buf.length); + } } } } return super.loadClass(name); - } catch (IOException e) { - JRuleLog.warn(logger, LOG_NAME_HANDLER, e.getMessage()); + JRuleLog.warn(logger, LOG_NAME_HANDLER, "Trouble loading class {}: {}", name, e.toString()); return super.loadClass(name); } }