Track origin of warnings from ""

Dear Community,

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 ] [] - Dispatching/filtering event for subscriber '' failed: begin 14, end 13, length 32
java.lang.StringIndexOutOfBoundsException: begin 14, end 13, length 32
        at java.lang.String.checkBoundsBeginEnd( ~[?:?]
        at java.lang.String.substring( ~[?:?]
        at ~[?:?]
        at$0( ~[?:?]
        at java.util.concurrent.Executors$ [?:?]
        at [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker( [?:?]
        at java.util.concurrent.ThreadPoolExecutor$ [?:?]
        at [?:?]

Thank you,

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:

            String ruleId = topic.substring(RULES_TOPIC_PREFIX.length(), topic.indexOf(RULES_TOPIC_SUFFIX));

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.

1 Like

Hey Rich,

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.

Again, Thanks a lot for looking into this.


Hi Rich and Alex,

Thanks to this post I’ve managed to get rid of those warnings in my code! The key was the line pointed by Rich:

String ruleId = topic.substring(RULES_TOPIC_PREFIX.length(), topic.indexOf(RULES_TOPIC_SUFFIX));

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.


1 Like

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.

Hi Rich,

Filled my first github issue, I hope there’s enough information for someone to solve this.


Hi Xanfia,

welcome to the community.

I in fact have a rule file called stateofday.rules, renaming this rule actually seemed to have fixed the issue.

Thank you very much for your analysis and input.


I think it should be fixed by this PR. :slight_smile: