openhab/openhab-core

[ephemeris] Calls to `isBankHoliday` failing with exception

Closed this issue · 6 comments

Expected Behavior

When calling isBankHoliday a boolean is returned, not an exception being thrown.

Current Behavior

Each of the following JS Scripting lines generate the following error.

actions.Ephemeris.isBankHoliday();
actions.Ephemeris.isBankHoliday(0);
actions.Ephemeris.isBankHoliday(time.toZDT('P2D'));
2024-05-21 09:38:56.637 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'scratchpad' failed: java.lang.Exception: java.lang.NoClassDefFoundError: Could not initialize class de.focus_shift.jollyday.core.HolidayManager 

Attempting to run one of these lines in a timer gives a stack trace:

2024-05-21 09:30:07.362 [WARN ] [ore.internal.scheduler.SchedulerImpl] - Scheduled job 'ui.timeStateMachine.debounce' failed and stopped                                                                                                                                                                                    org.graalvm.polyglot.PolyglotException: Could not initialize class de.focus_shift.jollyday.core.HolidayManager
        at org.openhab.core.ephemeris.internal.EphemerisManagerImpl.getHolidayManager(EphemerisManagerImpl.java:246) ~[?:?]
        at org.openhab.core.ephemeris.internal.EphemerisManagerImpl.isBankHoliday(EphemerisManagerImpl.java:289) ~[?:?]
        at org.openhab.core.model.script.actions.Ephemeris.isBankHoliday(Ephemeris.java:75) ~[bundleFile:?]
        at org.openhab.core.model.script.actions.Ephemeris.isBankHoliday(Ephemeris.java:70) ~[bundleFile:?]
        at <js>.getTodayItems(<eval>:162) ~[?:?]
        at <js>.createTimersGenerator(<eval>:213) ~[?:?]
        at <js>.:=>(/openhab/conf/automation/js/node_modules/openhab_rules_tools/timerMgr.js:66) ~[?:?]
        at <js>.callbackFn(/node_modules/openhab.js:2) ~[?:?]
        at com.oracle.truffle.polyglot.PolyglotFunctionProxyHandler.invoke(PolyglotFunctionProxyHandler.java:154) ~[bundleFile:?]
        at jdk.proxy1.$Proxy619.run(Unknown Source) ~[?:?]
        at org.openhab.automation.jsscripting.internal.threading.ThreadsafeTimers.lambda$0(ThreadsafeTimers.java:85) ~[bundleFile:?]
        at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$12(SchedulerImpl.java:189) ~[?:?]
        at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$1(SchedulerImpl.java:88) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) [?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
        at java.lang.Thread.run(Thread.java:840) [?:?]

Interestingly if you pass a custom XML file to the call there is no error.

I do not know if this is related to another error reported here.

Possible Solution

I can't see any changes to Ephemeris between OH 4.2 M2 and M3 to Ephemeris so the root cause is somewhat of a mystery to me.

Steps to Reproduce (for Bugs)

  1. Create a Script that calls the isBankHoliday() Action
  2. Run the Script

Context

This breaks my Time State Machine rule template: https://community.openhab.org/t/time-based-state-machine-4-0-0-0-4-9-9-9/144208 and has been reported on the 4.2 milestone thread by others.

Your Environment

  • Version used: openHAB 4.2 M3
  • Environment name and version (e.g. Chrome 111, Java 17, Node.js 18.15, ...): Unmodified Official Docker Image
  • Operating System and version (desktop or mobile, Windows 11, Raspbian Bullseye, ...): Unmodified Official Docker Image

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-4-2-milestone-discussion/154316/137

This is a class-loading issue, introduced by upgrading jollyday in #4178. With focus-shift/jollyday#438 the way resources are loaded from the classpath changed. de.focus_shift.jollyday.core.util.ClassLoadingUtil uses Thread.currentThread().getContextClassloader() to get the classloader and that is not a good way when the library is used in an OSGi environment. If I change it to ClassLoadingUtil.class.getClassLoader() everything works fine. I already checked if upgrading to 0.28.0 would solve the issue, but it does not, the code is still the same.

FTR: focus-shift/jollyday#538

We need to upgrade jollyday after this has been merged.

@J-N-K : should we revert the version upgrade or do you think that the fix and release on jollyday side could occur soon ?

@J-N-K : should we revert the version upgrade or do you think that the fix and release on jollyday side could occur soon ?

Hey, I am the maintainer of the https://github.com/focus-shift/jollyday/ library. I will provide a fix tomorrow with the version 0.28.1.

0.28.1 has been released with your fix.

I think it will appear on maven central in about 30 minutes.