Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[airq] StringIndexOutOfBoundsException on empty usercalib #13928

Closed
MikeTheTux opened this issue Dec 12, 2022 · 5 comments
Closed

[airq] StringIndexOutOfBoundsException on empty usercalib #13928

MikeTheTux opened this issue Dec 12, 2022 · 5 comments
Labels
bug An unexpected problem or unintended behavior of an add-on

Comments

@MikeTheTux
Copy link
Contributor

MikeTheTux commented Dec 12, 2022

The binding throws a StringIndexOutOfBoundsException. I guess it happens in case of empty "usercalib":{}:

Trace:

...
2022-12-12 14:56:04.660 [DEBUG] [ab.binding.airq.internal.AirqHandler] - air-Q - airqHandler - getConfigData(): decObj={"mqtt":null, ... "usercalib":{}, ...}
...
2022-12-12 14:56:04.687 [TRACE] [ab.binding.airq.internal.AirqHandler] - air-Q - airqHandler - processType(): airqName=usercalib, channelName=userCalib, type=calib
2022-12-12 14:56:04.688 [WARN ] [ab.binding.airq.internal.AirqHandler] - air-Q - airqHandler - getConfigData(): Error in processConfigData(): java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 0
...

Your Environment

openHAB 3.4.0.M4
My air-Q is actually quiet new. I did not perform any calibration. It is used without beeing connected to the cloud.

@MikeTheTux MikeTheTux added the bug An unexpected problem or unintended behavior of an add-on label Dec 12, 2022
@MikeTheTux
Copy link
Contributor Author

The same issue was already reported here: https://community.openhab.org/t/new-air-q-binding/115989/6

@MikeTheTux
Copy link
Contributor Author

MikeTheTux commented Dec 17, 2022

The following length-check in the java code of the binding fixes the issue:

if (str.length() >= 1) {
    updateState(channelName, new StringType(str.substring(0, str.length() - 1)));
} else {
    logger.trace(
            "air-Q - airqHandler - processType(): Cannot extract calibration data from this string: {}",
            dec.get(airqName).toString());
}

I'm thinking of creating a PR with those changes.

@lolodomo
Copy link
Contributor

Rather str.isEmpty()

@MikeTheTux
Copy link
Contributor Author

Rather str.isEmpty()

In that case that would be the better choice, but there are other cases that need to check for a min lenght of 2:

if (arrstr.length() >= 2) {
    logger.trace("air-Q - airqHandler - processType(): property array {} set to {}",
            channelName, arrstr.substring(0, arrstr.length() - 2));
    getThing().setProperty(channelName, arrstr.substring(0, arrstr.length() - 2));
} else {
    logger.trace("air-Q - airqHandler - processType(): cannot handle this as an array: {}",
            proparr);
}

@lolodomo
Copy link
Contributor

Closed by merged PR #14000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

No branches or pull requests

2 participants