openhab / openhab1-addons

Add-ons for openHAB 1.x
Eclipse Public License 2.0
3.43k stars 1.7k forks source link

Jsr223: Bug when loading a new script or a modify one. #4011

Open dodger777 opened 8 years ago

dodger777 commented 8 years ago

When you modify a script or create a new one, some time it load and tell that the getRules do not exist, when it clearly exist.

Touching the file would work on 99.99% of the case.

This is a fairly frequent bug.

Seen using groovy script.

dodger777 commented 8 years ago

Error exemple:

java.lang.NoSuchMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getRules() is applicable for argument types
: () values: []
Possible solutions: getClass()
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.invokeImpl(GroovyScriptEngineImpl.java:403) ~[groovy-jsr223-2.4.5.jar:2.4.5]
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.invokeFunction(GroovyScriptEngineImpl.java:200) ~[groovy-jsr223-2.4.5.jar:2.4.5]
        at org.openhab.core.jsr223.internal.engine.scriptmanager.Script.loadScript(Script.java:93) ~[bundlefile:na]
        at org.openhab.core.jsr223.internal.engine.scriptmanager.Script.<init>(Script.java:79) ~[bundlefile:na]
        at org.openhab.core.jsr223.internal.engine.scriptmanager.ScriptManager.loadScript(ScriptManager.java:90) [bundlefile:na]
        at org.openhab.core.jsr223.internal.engine.scriptmanager.ScriptManager.scriptsChanged(ScriptManager.java:185) [bundlefile:na]
        at org.openhab.core.jsr223.internal.engine.scriptmanager.ScriptUpdateWatcher.run(ScriptUpdateWatcher.java:105) [bundlefile:na]
        at java.lang.Thread.run(Unknown Source) [na:1.8.0_25]
steve-bate commented 8 years ago

This can happen because the Java file change events cause the binding to read the file before it is completely saved to the disk. It's more likely to happen if you have large rule/script files, a slow disk or saving a file over a network and so on. The code should be changed to retry the script load at least a few times (or check if the file size is changing) before propagating the exception.