KAFKA-15152: Fix incorrect format specifiers when formatting string (#14026)

Reviewers: Divij Vaidya <diviv@amazon.com>

Co-authored-by: phuchong.tran <phuchong.tran@servicenow.com>
This commit is contained in:
Phuc-Hong-Tran 2023-08-25 03:38:45 +10:00 committed by GitHub
parent 45aae641a5
commit 8d12c1175c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 16 additions and 16 deletions

View File

@ -1228,7 +1228,7 @@ public class KafkaAdminClient extends AdminClient {
call.fail(now, authException); call.fail(now, authException);
} else { } else {
call.fail(now, new DisconnectException(String.format( call.fail(now, new DisconnectException(String.format(
"Cancelled %s request with correlation id %s due to node %s being disconnected", "Cancelled %s request with correlation id %d due to node %s being disconnected",
call.callName, correlationId, response.destination()))); call.callName, correlationId, response.destination())));
} }
} else { } else {

View File

@ -438,7 +438,7 @@ public class MemoryRecordsBuilder implements AutoCloseable {
throw new IllegalArgumentException("Control records can only be appended to control batches"); throw new IllegalArgumentException("Control records can only be appended to control batches");
if (lastOffset != null && offset <= lastOffset) if (lastOffset != null && offset <= lastOffset)
throw new IllegalArgumentException(String.format("Illegal offset %s following previous offset %s " + throw new IllegalArgumentException(String.format("Illegal offset %d following previous offset %d " +
"(Offsets must increase monotonically).", offset, lastOffset)); "(Offsets must increase monotonically).", offset, lastOffset));
if (timestamp < 0 && timestamp != RecordBatch.NO_TIMESTAMP) if (timestamp < 0 && timestamp != RecordBatch.NO_TIMESTAMP)

View File

@ -272,7 +272,7 @@ public class HttpAccessTokenRetriever implements AccessTokenRetriever {
errorResponseBody); errorResponseBody);
if (responseBody == null || responseBody.isEmpty()) if (responseBody == null || responseBody.isEmpty())
throw new IOException(String.format("The token endpoint response was unexpectedly empty despite response code %s from %s and error message %s", throw new IOException(String.format("The token endpoint response was unexpectedly empty despite response code %d from %s and error message %s",
responseCode, con.getURL(), formatErrorMessage(errorResponseBody))); responseCode, con.getURL(), formatErrorMessage(errorResponseBody)));
return responseBody; return responseBody;
@ -337,7 +337,7 @@ public class HttpAccessTokenRetriever implements AccessTokenRetriever {
if (snippet.length() > MAX_RESPONSE_BODY_LENGTH) { if (snippet.length() > MAX_RESPONSE_BODY_LENGTH) {
int actualLength = responseBody.length(); int actualLength = responseBody.length();
String s = responseBody.substring(0, MAX_RESPONSE_BODY_LENGTH); String s = responseBody.substring(0, MAX_RESPONSE_BODY_LENGTH);
snippet = String.format("%s (trimmed to first %s characters out of %s total)", s, MAX_RESPONSE_BODY_LENGTH, actualLength); snippet = String.format("%s (trimmed to first %d characters out of %d total)", s, MAX_RESPONSE_BODY_LENGTH, actualLength);
} }
throw new IOException(String.format("The token endpoint response did not contain an access_token value. Response: (%s)", snippet)); throw new IOException(String.format("The token endpoint response did not contain an access_token value. Response: (%s)", snippet));

View File

@ -348,8 +348,8 @@ public final class RefreshingHttpsJwks implements Initable, Closeable {
// 1. Don't try to resolve the key as the large ID will sit in our cache // 1. Don't try to resolve the key as the large ID will sit in our cache
// 2. Report the issue in the logs but include only the first N characters // 2. Report the issue in the logs but include only the first N characters
int actualLength = keyId.length(); int actualLength = keyId.length();
String s = keyId.substring(0, MISSING_KEY_ID_MAX_KEY_LENGTH); String trimmedKeyId = keyId.substring(0, MISSING_KEY_ID_MAX_KEY_LENGTH);
String snippet = String.format("%s (trimmed to first %s characters out of %s total)", s, MISSING_KEY_ID_MAX_KEY_LENGTH, actualLength); String snippet = String.format("%s (trimmed to first %d characters out of %d total)", trimmedKeyId, MISSING_KEY_ID_MAX_KEY_LENGTH, actualLength);
log.warn("Key ID {} was too long to cache", snippet); log.warn("Key ID {} was too long to cache", snippet);
return false; return false;
} else { } else {

View File

@ -44,7 +44,7 @@ public class SerializedJwt {
String[] splits = token.split("\\."); String[] splits = token.split("\\.");
if (splits.length != 3) if (splits.length != 3)
throw new ValidateException(String.format("Malformed JWT provided (%s); expected three sections (header, payload, and signature), but %s sections provided", throw new ValidateException(String.format("Malformed JWT provided (%s); expected three sections (header, payload, and signature), but %d sections provided",
token, splits.length)); token, splits.length));
this.token = token.trim(); this.token = token.trim();

View File

@ -55,7 +55,7 @@ final class ControllerResultAndOffset<T> extends ControllerResult<T> {
@Override @Override
public String toString() { public String toString() {
return String.format( return String.format(
"ControllerResultAndOffset(records=%s, response=%s, isAtomic=%s, offset=%s)", "ControllerResultAndOffset(records=%s, response=%s, isAtomic=%s, offset=%d)",
String.join(",", records().stream().map(ApiMessageAndVersion::toString).collect(Collectors.toList())), String.join(",", records().stream().map(ApiMessageAndVersion::toString).collect(Collectors.toList())),
response(), response(),
isAtomic(), isAtomic(),

View File

@ -168,7 +168,7 @@ public final class Batch<T> implements Iterable<T> {
if (records.isEmpty()) { if (records.isEmpty()) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
String.format( String.format(
"Control batch must contain at least one record; baseOffset = %s; epoch = %s", "Control batch must contain at least one record; baseOffset = %d; epoch = %d",
baseOffset, baseOffset,
epoch epoch
) )
@ -205,7 +205,7 @@ public final class Batch<T> implements Iterable<T> {
if (records.isEmpty()) { if (records.isEmpty()) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
String.format( String.format(
"Batch must contain at least one record; baseOffset = %s; epoch = %s", "Batch must contain at least one record; baseOffset = %d; epoch = %d",
baseOffset, baseOffset,
epoch epoch
) )

View File

@ -118,12 +118,12 @@ public class FollowerState implements EpochState {
if (updatedHighWatermark < 0) { if (updatedHighWatermark < 0) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
String.format("Illegal negative (%s) high watermark update", updatedHighWatermark) String.format("Illegal negative (%d) high watermark update", updatedHighWatermark)
); );
} else if (previousHighWatermark > updatedHighWatermark) { } else if (previousHighWatermark > updatedHighWatermark) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
String.format( String.format(
"Non-monotonic update of high watermark from %s to %s", "Non-monotonic update of high watermark from %d to %d",
previousHighWatermark, previousHighWatermark,
updatedHighWatermark updatedHighWatermark
) )

View File

@ -99,7 +99,7 @@ public interface ReplicatedLog extends AutoCloseable {
*/ */
OffsetAndEpoch latestSnapshotId = latestSnapshotId().orElseThrow(() -> new IllegalStateException( OffsetAndEpoch latestSnapshotId = latestSnapshotId().orElseThrow(() -> new IllegalStateException(
String.format( String.format(
"Log start offset (%s) is greater than zero but latest snapshot was not found", "Log start offset (%d) is greater than zero but latest snapshot was not found",
startOffset() startOffset()
) )
)); ));

View File

@ -328,7 +328,7 @@ public class BatchBuilder<T> {
if (expectedNextOffset - baseOffset >= Integer.MAX_VALUE) { if (expectedNextOffset - baseOffset >= Integer.MAX_VALUE) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
String.format( String.format(
"Adding %s records to a batch with base offset of %s and next offset of %s", "Adding %d records to a batch with base offset of %d and next offset of %d",
records.size(), records.size(),
baseOffset, baseOffset,
expectedNextOffset expectedNextOffset

View File

@ -101,8 +101,8 @@ public class CopartitionedTopicsEnforcer {
.orElseThrow(emptyNumberOfPartitionsExceptionSupplier(config.name())); .orElseThrow(emptyNumberOfPartitionsExceptionSupplier(config.name()));
if (numberOfPartitionsOfInternalTopic != numPartitionsToUseForRepartitionTopics) { if (numberOfPartitionsOfInternalTopic != numPartitionsToUseForRepartitionTopics) {
final String msg = String.format("%sNumber of partitions [%s] of repartition topic [%s] " + final String msg = String.format("%sNumber of partitions [%d] of repartition topic [%s] " +
"doesn't match number of partitions [%s] of the source topic.", "doesn't match number of partitions [%d] of the source topic.",
logPrefix, logPrefix,
numberOfPartitionsOfInternalTopic, numberOfPartitionsOfInternalTopic,
config.name(), config.name(),