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
1 changed files with 23 additions and 7 deletions

View File

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