Fix various Error Prone errors that were found by the FOSS build

Most common:
- Unnecessary parentheses and operator precedence clarify (self-explanatory)
- Reference equality--there were a few instances of using == or != improperly
- Qualification of Builder (and similar) imports so that it's clear which type of Builder we're referring to
- Marking some immutable classes with @Immutable since EP desires that all enums be deeply immutable
- String.split() having "surprising behavior"

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=230971531
This commit is contained in:
gbrodman 2019-01-25 14:39:57 -08:00 committed by Ben McIlwain
parent 9cd37189c2
commit 3cf26ff9b6
52 changed files with 155 additions and 133 deletions

View file

@ -11,6 +11,7 @@ java_library(
deps = [
"//java/google/registry/util",
"//third_party/objectify:objectify-v4_1",
"@com_google_errorprone_error_prone_annotations",
"@com_google_guava",
"@com_google_re2j",
],

View file

@ -19,13 +19,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableRangeSet;
import com.google.common.collect.Range;
import com.google.common.collect.RangeSet;
import com.google.errorprone.annotations.Immutable;
import com.google.re2j.Matcher;
import com.google.re2j.Pattern;
import java.net.URI;
import java.util.Optional;
/** An IDN table for a particular TLD. */
@Immutable
public final class IdnTable {
/** Regular expression to match a line of an IDN table. */
@ -48,8 +49,8 @@ public final class IdnTable {
/** Public URL of policy for this IDN table, which is needed by RDE. */
private final URI policy;
/** {@link RangeSet} containing the valid codepoints in this table. */
private final RangeSet<Integer> validCodepoints;
/** {@link ImmutableRangeSet} containing the valid codepoints in this table. */
private final ImmutableRangeSet<Integer> validCodepoints;
/** Validates the language rules associated with this IDN table. */
private final Optional<LanguageValidator> languageValidator;
@ -58,7 +59,7 @@ public final class IdnTable {
String name,
URI url,
URI policy,
RangeSet<Integer> validCodepoints,
ImmutableRangeSet<Integer> validCodepoints,
Optional<LanguageValidator> languageValidator) {
this.name = name;
this.url = checkNotNull(url, "%s missing '# URL: http://foo.example/page' line", name);

View file

@ -22,12 +22,15 @@ import static java.lang.Character.UnicodeBlock.KATAKANA;
import com.google.common.collect.ImmutableRangeSet;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Range;
import com.google.errorprone.annotations.Immutable;
import java.lang.Character.UnicodeBlock;
import java.util.Objects;
/**
* Validates Japanese language domain labels. This class should only be used with a Japanese
* language IDN table.
*/
@Immutable
class JapaneseLanguageValidator extends LanguageValidator {
/** Any string with Japanese characters can have at most 15 characters. */
@ -82,7 +85,8 @@ class JapaneseLanguageValidator extends LanguageValidator {
// The KATAKANA_HIRAGANA_PROLONGED_SOUND_MARK can only occur after a HIRAGANA or KATAKANA
// character.
if (codepoint == KATAKANA_HIRAGANA_PROLONGED_SOUND_MARK
&& precedingUnicodeBlock != HIRAGANA && precedingUnicodeBlock != KATAKANA) {
&& !Objects.equals(precedingUnicodeBlock, HIRAGANA)
&& !Objects.equals(precedingUnicodeBlock, KATAKANA)) {
return false;
}

View file

@ -15,8 +15,10 @@
package google.registry.tldconfig.idn;
import com.google.common.collect.ImmutableMap;
import com.google.errorprone.annotations.Immutable;
import java.util.Optional;
@Immutable
abstract class LanguageValidator {
/** A registry of all known language validators keyed by their language code. */