fixed potential StringIndexOutOfBoundsExceptions (#14000)

fixed compiler warnings

Signed-off-by: Michael Weger <weger.michael@gmx.net>
This commit is contained in:
MikeTheTux 2022-12-18 13:35:08 +01:00 committed by GitHub
parent debdfa5f8b
commit 6dd8cd52c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -268,7 +268,7 @@ public class AirqHandler extends BaseThingHandler {
break;
case "logLevel":
String ll = command.toString();
if (ll.equals("Error") || ll.equals("Warning") || ll.equals("Info")) {
if ("Error".equals(ll) || "Warning".equals(ll) || "Info".equals(ll)) {
newobj.addProperty("logging", ll);
changeSettings(newobj);
} else {
@ -288,7 +288,7 @@ public class AirqHandler extends BaseThingHandler {
break;
case "powerFreqSuppression":
String newFreq = command.toString();
if (newFreq.equals("50Hz") || newFreq.equals("60Hz") || newFreq.equals("50Hz+60Hz")) {
if ("50Hz".equals(newFreq) || "60Hz".equals(newFreq) || "50Hz+60Hz".equals(newFreq)) {
newobj.addProperty("Rejection", newFreq);
changeSettings(newobj);
} else {
@ -710,7 +710,12 @@ public class AirqHandler extends BaseThingHandler {
for (JsonElement el : arr) {
str.append(el.getAsString() + ", ");
}
if (str.length() >= 2) {
updateState(channelName, new StringType(str.substring(0, str.length() - 2)));
} else {
logger.trace("air-Q - airqHandler - processType(): cannot handle this as an array: {}",
jsonarr);
}
} else {
logger.warn("air-Q - airqHandler - processType(): cannot handle this as an array: {}", jsonarr);
}
@ -730,7 +735,13 @@ public class AirqHandler extends BaseThingHandler {
str = str + attributeName + ": offset=" + attributeValue.get("offset").getAsString() + " ["
+ timecalibString + "]";
}
if (!str.isEmpty()) {
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());
}
} else {
logger.warn(
"air-Q - airqHandler - processType(): Cannot extract calibration data from this string: {}",
@ -749,9 +760,14 @@ public class AirqHandler extends BaseThingHandler {
for (JsonElement el : arr) {
arrstr = arrstr + el.getAsString() + ", ";
}
logger.trace("air-Q - airqHandler - processType(): property array {} set to {}", channelName,
arrstr.substring(0, arrstr.length() - 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);
}
} else {
logger.warn("air-Q - airqHandler - processType(): cannot handle this as an array: {}", proparr);
}