Skip to content

Commit

Permalink
fixed potential StringIndexOutOfBoundsExceptions (openhab#14000)
Browse files Browse the repository at this point in the history
fixed compiler warnings

Signed-off-by: Michael Weger <[email protected]>
  • Loading branch information
MikeTheTux authored Dec 18, 2022
1 parent debdfa5 commit 6dd8cd5
Showing 1 changed file with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
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 {
Expand All @@ -288,7 +288,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
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 {
Expand Down Expand Up @@ -710,7 +710,12 @@ private void processType(JsonObject dec, String airqName, String channelName, St
for (JsonElement el : arr) {
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 {
logger.warn("air-Q - airqHandler - processType(): cannot handle this as an array: {}", jsonarr);
}
Expand All @@ -730,7 +735,13 @@ private void processType(JsonObject dec, String airqName, String channelName, St
str = str + attributeName + ": offset=" + attributeValue.get("offset").getAsString() + " ["
+ 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 {
logger.warn(
"air-Q - airqHandler - processType(): Cannot extract calibration data from this string: {}",
Expand All @@ -749,9 +760,14 @@ private void processType(JsonObject dec, String airqName, String channelName, St
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));
getThing().setProperty(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);
}
Expand Down

0 comments on commit 6dd8cd5

Please sign in to comment.