Skip to content

Commit

Permalink
Fix lenient format strings in common.
Browse files Browse the repository at this point in the history
RELNOTES=N/A
PiperOrigin-RevId: 469179783
  • Loading branch information
java-team-github-bot authored and Google Java Core Libraries committed Aug 22, 2022
1 parent e9755b4 commit 4312d94
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @author Kevin Bourrillion
* @author Jared Levy
*/
@SuppressWarnings("LenientFormatStringValidation") // Intentional for testing
@GwtCompatible(emulated = true)
public class PreconditionsTest extends TestCase {
public void testCheckArgument_simple_success() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public void testValidSurrogatePairAt() {
assertFalse(Strings.validSurrogatePairAt("\uD8ABx", 0));
}

@SuppressWarnings("LenientFormatStringValidation") // Intentional for testing.
public void testLenientFormat() {
assertEquals("%s", Strings.lenientFormat("%s"));
assertEquals("5", Strings.lenientFormat("%s", 5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ public <K1 extends K, V1 extends V> CacheBuilder<K1, V1> weigher(
if (strictParsing) {
checkState(
this.maximumSize == UNSET_INT,
"weigher can not be combined with maximum size",
"weigher can not be combined with maximum size (%s provided)",
this.maximumSize);
}

Expand Down
14 changes: 8 additions & 6 deletions android/guava/src/com/google/common/cache/CacheBuilderSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ static class InitialCapacityParser extends IntegerParser {
protected void parseInteger(CacheBuilderSpec spec, int value) {
checkArgument(
spec.initialCapacity == null,
"initial capacity was already set to ",
"initial capacity was already set to %s",
spec.initialCapacity);
spec.initialCapacity = value;
}
Expand All @@ -338,9 +338,10 @@ protected void parseInteger(CacheBuilderSpec spec, int value) {
static class MaximumSizeParser extends LongParser {
@Override
protected void parseLong(CacheBuilderSpec spec, long value) {
checkArgument(spec.maximumSize == null, "maximum size was already set to ", spec.maximumSize);
checkArgument(
spec.maximumWeight == null, "maximum weight was already set to ", spec.maximumWeight);
spec.maximumSize == null, "maximum size was already set to %s", spec.maximumSize);
checkArgument(
spec.maximumWeight == null, "maximum weight was already set to %s", spec.maximumWeight);
spec.maximumSize = value;
}
}
Expand All @@ -350,8 +351,9 @@ static class MaximumWeightParser extends LongParser {
@Override
protected void parseLong(CacheBuilderSpec spec, long value) {
checkArgument(
spec.maximumWeight == null, "maximum weight was already set to ", spec.maximumWeight);
checkArgument(spec.maximumSize == null, "maximum size was already set to ", spec.maximumSize);
spec.maximumWeight == null, "maximum weight was already set to %s", spec.maximumWeight);
checkArgument(
spec.maximumSize == null, "maximum size was already set to %s", spec.maximumSize);
spec.maximumWeight = value;
}
}
Expand All @@ -362,7 +364,7 @@ static class ConcurrencyLevelParser extends IntegerParser {
protected void parseInteger(CacheBuilderSpec spec, int value) {
checkArgument(
spec.concurrencyLevel == null,
"concurrency level was already set to ",
"concurrency level was already set to %s",
spec.concurrencyLevel);
spec.concurrencyLevel = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @author Kevin Bourrillion
* @author Jared Levy
*/
@SuppressWarnings("LenientFormatStringValidation") // Intentional for testing
@GwtCompatible(emulated = true)
public class PreconditionsTest extends TestCase {
public void testCheckArgument_simple_success() {
Expand Down
1 change: 1 addition & 0 deletions guava-tests/test/com/google/common/base/StringsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public void testValidSurrogatePairAt() {
assertFalse(Strings.validSurrogatePairAt("\uD8ABx", 0));
}

@SuppressWarnings("LenientFormatStringValidation") // Intentional for testing.
public void testLenientFormat() {
assertEquals("%s", Strings.lenientFormat("%s"));
assertEquals("5", Strings.lenientFormat("%s", 5));
Expand Down
2 changes: 1 addition & 1 deletion guava/src/com/google/common/cache/CacheBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ public <K1 extends K, V1 extends V> CacheBuilder<K1, V1> weigher(
if (strictParsing) {
checkState(
this.maximumSize == UNSET_INT,
"weigher can not be combined with maximum size",
"weigher can not be combined with maximum size (%s provided)",
this.maximumSize);
}

Expand Down
14 changes: 8 additions & 6 deletions guava/src/com/google/common/cache/CacheBuilderSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ static class InitialCapacityParser extends IntegerParser {
protected void parseInteger(CacheBuilderSpec spec, int value) {
checkArgument(
spec.initialCapacity == null,
"initial capacity was already set to ",
"initial capacity was already set to %s",
spec.initialCapacity);
spec.initialCapacity = value;
}
Expand All @@ -338,9 +338,10 @@ protected void parseInteger(CacheBuilderSpec spec, int value) {
static class MaximumSizeParser extends LongParser {
@Override
protected void parseLong(CacheBuilderSpec spec, long value) {
checkArgument(spec.maximumSize == null, "maximum size was already set to ", spec.maximumSize);
checkArgument(
spec.maximumWeight == null, "maximum weight was already set to ", spec.maximumWeight);
spec.maximumSize == null, "maximum size was already set to %s", spec.maximumSize);
checkArgument(
spec.maximumWeight == null, "maximum weight was already set to %s", spec.maximumWeight);
spec.maximumSize = value;
}
}
Expand All @@ -350,8 +351,9 @@ static class MaximumWeightParser extends LongParser {
@Override
protected void parseLong(CacheBuilderSpec spec, long value) {
checkArgument(
spec.maximumWeight == null, "maximum weight was already set to ", spec.maximumWeight);
checkArgument(spec.maximumSize == null, "maximum size was already set to ", spec.maximumSize);
spec.maximumWeight == null, "maximum weight was already set to %s", spec.maximumWeight);
checkArgument(
spec.maximumSize == null, "maximum size was already set to %s", spec.maximumSize);
spec.maximumWeight = value;
}
}
Expand All @@ -362,7 +364,7 @@ static class ConcurrencyLevelParser extends IntegerParser {
protected void parseInteger(CacheBuilderSpec spec, int value) {
checkArgument(
spec.concurrencyLevel == null,
"concurrency level was already set to ",
"concurrency level was already set to %s",
spec.concurrencyLevel);
spec.concurrencyLevel = value;
}
Expand Down

0 comments on commit 4312d94

Please sign in to comment.