mirror of
https://github.com/google/nomulus
synced 2026-09-20 06:54:43 +00:00
Enable new errorprone checks and fix violations (#3018)
This commit is contained in:
@@ -16,6 +16,8 @@ package google.registry.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.google.errorprone.annotations.FormatMethod;
|
||||
import com.google.errorprone.annotations.FormatString;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -41,9 +43,10 @@ public class PreconditionsUtils {
|
||||
}
|
||||
|
||||
/** Checks whether the provided reference is null, throws IAE if it is, and returns it if not. */
|
||||
@FormatMethod
|
||||
public static <T> T checkArgumentNotNull(
|
||||
@Nullable T reference,
|
||||
@Nullable String errorMessageTemplate,
|
||||
@Nullable @FormatString String errorMessageTemplate,
|
||||
@Nullable Object... errorMessageArgs) {
|
||||
checkArgument(reference != null, errorMessageTemplate, errorMessageArgs);
|
||||
return reference;
|
||||
@@ -65,9 +68,10 @@ public class PreconditionsUtils {
|
||||
}
|
||||
|
||||
/** Checks if the provided Optional is present, returns its value if so, and throws IAE if not. */
|
||||
@FormatMethod
|
||||
public static <T> T checkArgumentPresent(
|
||||
@Nullable Optional<T> reference,
|
||||
@Nullable String errorMessageTemplate,
|
||||
@Nullable @FormatString String errorMessageTemplate,
|
||||
@Nullable Object... errorMessageArgs) {
|
||||
checkArgumentNotNull(reference, errorMessageTemplate, errorMessageArgs);
|
||||
checkArgument(reference.isPresent(), errorMessageTemplate, errorMessageArgs);
|
||||
|
||||
@@ -81,9 +81,9 @@ public final class SqlTemplate {
|
||||
String key = matcher.group(2);
|
||||
String rightQuote = matcher.group(3);
|
||||
String value = substitutions.get(key);
|
||||
checkArgumentNotNull(value, "%%s% found in template but no substitution specified", key);
|
||||
checkArgumentNotNull(value, "%s found in template but no substitution specified", wholeMatch);
|
||||
checkArgument(leftQuote.equals(rightQuote), "Quote mismatch: %s", wholeMatch);
|
||||
matcher.appendReplacement(result, String.format("%s%s%s", leftQuote, value, rightQuote));
|
||||
matcher.appendReplacement(result, leftQuote + value + rightQuote);
|
||||
found.add(key);
|
||||
}
|
||||
matcher.appendTail(result);
|
||||
|
||||
@@ -82,7 +82,7 @@ class SerializeUtilsTest {
|
||||
|
||||
@Test
|
||||
void testStringifyParse_longValue_maintainsValue() {
|
||||
assertThat(parse(Serializable.class, stringify((long) 12345))).isEqualTo((long) 12345);
|
||||
assertThat(parse(Serializable.class, stringify(12345L))).isEqualTo(12345L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user