I am receiving the following error in openhab.log files. It seems that I have some kind of issue were I go out of bound of a string array in my rules. The question is how do I pinpoint the originating rule of this error? Is there an easy way to figure that out?
21-08-10 13:00:00.919 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching/filtering event for subscriber 'org.openhab.core.events.EventSubscriber' failed: begin 14, end 13, length 32
java.lang.StringIndexOutOfBoundsException: begin 14, end 13, length 32
at java.lang.String.checkBoundsBeginEnd(String.java:3319) ~[?:?]
at java.lang.String.substring(String.java:1874) ~[?:?]
at org.openhab.core.io.monitor.internal.metrics.RuleMetric.receive(RuleMetric.java:117) ~[?:?]
at org.openhab.core.internal.events.EventHandler.lambda$0(EventHandler.java:151) ~[?:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:829) [?:?]
One of the things that a lot of people don’t understand is that those big long stack traces that get printed to the logs actually provide useful information. I cringe every time I see someone trying to disable them.
Anyway, the error itself is not really coming directly from code you wrote necessarily. I don’t see any of the classes involved with running actual rules in this stack trace (this is the full stack trace, right?).
The root error is there is something trying to extract a part of a String that is 32 characters long. It’s trying to extract the characters starting at character 14 through character 13. That should throw up alarms because the end is before the beginning. So that’s what’s going wrong.
The first class that is actually a part of openHAB itself is RuleMetric and the error is taking place on line 117 of that class. Looking on GitHub I see the line is:
So far that tracks since the original error is a call to substring. That line of code is trying to extract the rule ID from the event’s topic. Based on the available information I’d guess that the event is coming from a rule that doesn’t have an ID at all.
That’s about as far as I can take you. Review all your rules. The best way would be to query for them in the REST API docs and see if you can find one or more that doesn’t have a rule ID defined or the ID is an empty string.
Theoretically this state should be impossible. Every entity in openHAB has a unique ID and it shouldn’t be possible for a rule to exist without an ID. So once you figure out which rule it is, review how you created it in the first place and/or things you may have done to it in the past to determine if an issue needs to be filed to prevent this from occurring.
thank you very much for the comprehensive reply. I would not try to disable stack traces, they provided a good starting point for analyzing issues in the past…and if something happens its usually too late to reactivate them.
All my rules are text file based and I haven’t actually created any in the through MainUi, I’m old-school like that. I started checking for rules without ID’s via Rest, but all results actually had an ID set which basically looked like light_automation-1, etc. That matches what I see in the UI.
I’m now trying to reference the occurence of the error with events that might happen around that time and see if I can identify patterm. Will update the thread once I find the culprit.
which uses two constant string to find the begining and the end of the ruleId. This constants are
public static final String RULES_TOPIC_PREFIX = "openhab/rules/";
public static final String RULES_TOPIC_SUFFIX = "/state";
My rules are all DSL text files, so the uid of every rule is created from filename appending a number. The problem was that I had a file called stateMachines.rules, so all its internal rules had uids like:
So when the code in RuleMetric executes against the topic “openhab/rules/stateMachines-1/state” this warning shows up. My solution has been simple, just rename the file avoiding it to start with “state”.
Thank your very much for your time and hints. I hope this can help @HoLiuS also.
You might consider filing an issue to make the code that processes the rule ID a little more flexible than that. There are other approaches that wouldn’t have this same limitation including splitting the ID on “/” and only looking at the 3rd element. That should avoid the problem and you can have a .rules file that starts with state.