Fix String.format argument mismatches (#4008)

These argument mismatches cause wrong messages being logged and thrown in exceptions.

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2024-01-03 13:13:53 +01:00 committed by GitHub
parent 26a958cd4d
commit d162b82206
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 19 deletions

View File

@ -289,16 +289,14 @@ public class SysfsUsbSerialScanner implements UsbSerialScanner {
}
if (!canPerformScans()) {
String logString = String.format(
"Cannot perform scans with this configuration: sysfsTtyDevicesDirectory: {}, devDirectory: {}",
sysfsTtyDevicesDirectory, devDirectory);
String message = "Cannot perform scans with this configuration: sysfsTtyDevicesDirectory: {}, devDirectory: {}";
if (configurationIsChanged) {
// Warn if the configuration was actively changed
logger.warn(logString);
logger.warn(message, sysfsTtyDevicesDirectory, devDirectory);
} else {
// Otherwise, only debug log - so that, in particular, on Non-Linux systems users do not see warning
logger.debug(logString);
logger.debug(message, sysfsTtyDevicesDirectory, devDirectory);
}
}
}

View File

@ -88,7 +88,7 @@ public class Bin2Json {
try {
parser = JBBPParser.prepare(parserRule);
} catch (JBBPException e) {
throw new ConversionException(String.format("Illegal parser rule, reason: %s", e.getMessage(), e));
throw new ConversionException(String.format("Illegal parser rule, reason: %s", e.getMessage()), e);
}
}
@ -103,7 +103,7 @@ public class Bin2Json {
try {
return convert(HexUtils.hexToBytes(hexString));
} catch (IllegalArgumentException e) {
throw new ConversionException(String.format("Illegal hexstring , reason: %s", e.getMessage(), e));
throw new ConversionException(String.format("Illegal hexstring , reason: %s", e.getMessage()), e);
}
}
@ -117,10 +117,8 @@ public class Bin2Json {
public JsonObject convert(byte[] data) throws ConversionException {
try {
return convert(parser.parse(data));
} catch (IOException e) {
throw new ConversionException(String.format("Unexpected error, reason: %s", e.getMessage(), e));
} catch (JBBPException e) {
throw new ConversionException(String.format("Unexpected error, reason: %s", e.getMessage(), e));
} catch (IOException | JBBPException e) {
throw new ConversionException(String.format("Unexpected error, reason: %s", e.getMessage()), e);
}
}
@ -134,10 +132,8 @@ public class Bin2Json {
public JsonObject convert(InputStream inputStream) throws ConversionException {
try {
return convert(parser.parse(inputStream));
} catch (IOException e) {
throw new ConversionException(String.format("Unexpected error, reason: %s", e.getMessage(), e));
} catch (JBBPException e) {
throw new ConversionException(String.format("Unexpected error, reason: %s", e.getMessage(), e));
} catch (IOException | JBBPException e) {
throw new ConversionException(String.format("Unexpected error, reason: %s", e.getMessage()), e);
}
}
@ -151,7 +147,7 @@ public class Bin2Json {
}
return json;
} catch (JBBPException e) {
throw new ConversionException(String.format("Unexpected error, reason: %s", e.getMessage(), e));
throw new ConversionException(String.format("Unexpected error, reason: %s", e.getMessage()), e);
}
}

View File

@ -169,7 +169,7 @@ public final class WriteRequestJsonUtilities {
writeSingle.set(true);
if (valuesElem.size() != 1) {
throw new IllegalArgumentException(String
.format("Expecting single value with functionCode=%s, got: %d", functionCode, valuesElem));
.format("Expecting single value with functionCode=%s, got: %s", functionCode, valuesElem));
}
// fall-through to WRITE_MULTIPLE_COILS
case WRITE_MULTIPLE_COILS:
@ -189,7 +189,7 @@ public final class WriteRequestJsonUtilities {
writeSingle.set(true);
if (valuesElem.size() != 1) {
throw new IllegalArgumentException(String
.format("Expecting single value with functionCode=%s, got: %d", functionCode, valuesElem));
.format("Expecting single value with functionCode=%s, got: %s", functionCode, valuesElem));
}
// fall-through to WRITE_MULTIPLE_REGISTERS
case WRITE_MULTIPLE_REGISTERS: {

View File

@ -101,7 +101,7 @@ public class PercentTypeTest {
assertEquals(new PercentType("1"), new PercentType("1", locale));
assertEquals(new PercentType("12"), new PercentType("12", locale));
assertEquals(new PercentType("12.56"), new PercentType(String.format("12%s56", ds), locale));
assertEquals(new PercentType("100"), new PercentType(String.format("100", gs, gs), locale));
assertEquals(new PercentType("100"), new PercentType("100", locale));
});
}