Skip to content

Commit

Permalink
Enable error-prone checks for NonFinalStaticField (#14228)
Browse files Browse the repository at this point in the history
Co-authored-by: Dawid Weiss <[email protected]>
  • Loading branch information
msfroh and dweiss authored Feb 24, 2025
1 parent 27cf1e1 commit ce50d3a
Show file tree
Hide file tree
Showing 155 changed files with 527 additions and 447 deletions.
2 changes: 1 addition & 1 deletion gradle/validation/error-prone.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ allprojects { prj ->
// '-Xep:NonApiType:OFF', // noisy
// '-Xep:NonAtomicVolatileUpdate:OFF', // TODO: there are problems
// '-Xep:NonCanonicalType:OFF', // noisy
// '-Xep:NonFinalStaticField:OFF', // noisy
'-Xep:NonFinalStaticField:WARN',
'-Xep:NonOverridingEquals:WARN',
'-Xep:NotJavadoc:WARN',
'-Xep:NullOptional:WARN',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public Reader normalize(Reader input) {
}

// "source" => "target"
static Pattern p = Pattern.compile("\"(.*)\"\\s*=>\\s*\"(.*)\"\\s*$");
private static final Pattern p = Pattern.compile("\"(.*)\"\\s*=>\\s*\"(.*)\"\\s*$");

protected void parseRules(List<String> rules, NormalizeCharMap.Builder builder) {
for (String rule : rules) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class KStemData1 {
private KStemData1() {}

// KStemData1 ... KStemData8 are created from "head_word_list.txt"
static String[] data = {
static final String[] data = {
"aback", "abacus", "abandon", "abandoned", "abase",
"abash", "abate", "abattoir", "abbess", "abbey",
"abbot", "abbreviate", "abbreviation", "abc", "abdicate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
class KStemData2 {
private KStemData2() {}

static String[] data = {
static final String[] data = {
"cash", "cashew", "cashier", "cashmere", "casing",
"casino", "cask", "casket", "casque", "cassava",
"casserole", "cassette", "cassock", "cassowary", "cast",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
class KStemData3 {
private KStemData3() {}

static String[] data = {
static final String[] data = {
"distasteful", "distemper", "distempered", "distend", "distension",
"distil", "distill", "distillation", "distiller", "distillery",
"distinct", "distinction", "distinctive", "distinguish", "distinguishable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
class KStemData4 {
private KStemData4() {}

static String[] data = {
static final String[] data = {
"granular", "granulate", "granule", "grape", "grapefruit",
"grapeshot", "grapevine", "graph", "graphic", "graphical",
"graphically", "graphite", "graphology", "grapnel", "grapple",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
class KStemData5 {
private KStemData5() {}

static String[] data = {
static final String[] data = {
"lock", "locker", "locket", "lockjaw", "locknut",
"lockout", "locks", "locksmith", "lockstitch", "lockup",
"loco", "locomotion", "locomotive", "locum", "locus",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
class KStemData6 {
private KStemData6() {}

static String[] data = {
static final String[] data = {
"pedant", "pedantic", "pedantry", "peddle", "peddler",
"pederast", "pederasty", "pedestal", "pedestrian", "pediatrician",
"pediatrics", "pedicab", "pedicel", "pedicure", "pedigree",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
class KStemData7 {
private KStemData7() {}

static String[] data = {
static final String[] data = {
"rupee", "rupture", "rural", "ruritanian", "ruse",
"rush", "rushes", "rushlight", "rusk", "russet",
"rust", "rustic", "rusticate", "rustication", "rustle",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
class KStemData8 {
private KStemData8() {}

static String[] data = {
static final String[] data = {
"tenor", "tenpin", "tense", "tensile", "tension",
"tent", "tentacle", "tentative", "tenterhooks", "tenuity",
"tenuous", "tenure", "tepee", "tepid", "tequila",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,33 +642,32 @@ private static CharArrayMap<DictEntry> initializeDictHash() {
DictEntry entry;

CharArrayMap<DictEntry> d = new CharArrayMap<>(1000, false);
for (int i = 0; i < exceptionWords.length; i++) {
if (!d.containsKey(exceptionWords[i])) {
entry = new DictEntry(exceptionWords[i], true);
d.put(exceptionWords[i], entry);
for (String exceptionWord : exceptionWords) {
if (!d.containsKey(exceptionWord)) {
entry = new DictEntry(exceptionWord, true);
d.put(exceptionWord, entry);
} else {
throw new RuntimeException(
"Warning: Entry [" + exceptionWords[i] + "] already in dictionary 1");
"Warning: Entry [" + exceptionWord + "] already in dictionary 1");
}
}

for (int i = 0; i < directConflations.length; i++) {
if (!d.containsKey(directConflations[i][0])) {
entry = new DictEntry(directConflations[i][1], false);
d.put(directConflations[i][0], entry);
for (String[] directConflation : directConflations) {
if (!d.containsKey(directConflation[0])) {
entry = new DictEntry(directConflation[1], false);
d.put(directConflation[0], entry);
} else {
throw new RuntimeException(
"Warning: Entry [" + directConflations[i][0] + "] already in dictionary 2");
"Warning: Entry [" + directConflation[0] + "] already in dictionary 2");
}
}

for (int i = 0; i < countryNationality.length; i++) {
if (!d.containsKey(countryNationality[i][0])) {
entry = new DictEntry(countryNationality[i][1], false);
d.put(countryNationality[i][0], entry);
for (String[] strings : countryNationality) {
if (!d.containsKey(strings[0])) {
entry = new DictEntry(strings[1], false);
d.put(strings[0], entry);
} else {
throw new RuntimeException(
"Warning: Entry [" + countryNationality[i][0] + "] already in dictionary 3");
throw new RuntimeException("Warning: Entry [" + strings[0] + "] already in dictionary 3");
}
}

Expand All @@ -677,92 +676,90 @@ private static CharArrayMap<DictEntry> initializeDictHash() {
String[] array;
array = KStemData1.data;

for (int i = 0; i < array.length; i++) {
if (!d.containsKey(array[i])) {
d.put(array[i], defaultEntry);
for (String s : array) {
if (!d.containsKey(s)) {
d.put(s, defaultEntry);
} else {
throw new RuntimeException("Warning: Entry [" + array[i] + "] already in dictionary 4");
throw new RuntimeException("Warning: Entry [" + s + "] already in dictionary 4");
}
}

array = KStemData2.data;
for (int i = 0; i < array.length; i++) {
if (!d.containsKey(array[i])) {
d.put(array[i], defaultEntry);
for (String s : array) {
if (!d.containsKey(s)) {
d.put(s, defaultEntry);
} else {
throw new RuntimeException("Warning: Entry [" + array[i] + "] already in dictionary 4");
throw new RuntimeException("Warning: Entry [" + s + "] already in dictionary 4");
}
}

array = KStemData3.data;
for (int i = 0; i < array.length; i++) {
if (!d.containsKey(array[i])) {
d.put(array[i], defaultEntry);
for (String s : array) {
if (!d.containsKey(s)) {
d.put(s, defaultEntry);
} else {
throw new RuntimeException("Warning: Entry [" + array[i] + "] already in dictionary 4");
throw new RuntimeException("Warning: Entry [" + s + "] already in dictionary 4");
}
}

array = KStemData4.data;
for (int i = 0; i < array.length; i++) {
if (!d.containsKey(array[i])) {
d.put(array[i], defaultEntry);
for (String s : array) {
if (!d.containsKey(s)) {
d.put(s, defaultEntry);
} else {
throw new RuntimeException("Warning: Entry [" + array[i] + "] already in dictionary 4");
throw new RuntimeException("Warning: Entry [" + s + "] already in dictionary 4");
}
}

array = KStemData5.data;
for (int i = 0; i < array.length; i++) {
if (!d.containsKey(array[i])) {
d.put(array[i], defaultEntry);
for (String s : array) {
if (!d.containsKey(s)) {
d.put(s, defaultEntry);
} else {
throw new RuntimeException("Warning: Entry [" + array[i] + "] already in dictionary 4");
throw new RuntimeException("Warning: Entry [" + s + "] already in dictionary 4");
}
}

array = KStemData6.data;
for (int i = 0; i < array.length; i++) {
if (!d.containsKey(array[i])) {
d.put(array[i], defaultEntry);
for (String s : array) {
if (!d.containsKey(s)) {
d.put(s, defaultEntry);
} else {
throw new RuntimeException("Warning: Entry [" + array[i] + "] already in dictionary 4");
throw new RuntimeException("Warning: Entry [" + s + "] already in dictionary 4");
}
}

array = KStemData7.data;
for (int i = 0; i < array.length; i++) {
if (!d.containsKey(array[i])) {
d.put(array[i], defaultEntry);
for (String s : array) {
if (!d.containsKey(s)) {
d.put(s, defaultEntry);
} else {
throw new RuntimeException("Warning: Entry [" + array[i] + "] already in dictionary 4");
throw new RuntimeException("Warning: Entry [" + s + "] already in dictionary 4");
}
}

for (int i = 0; i < KStemData8.data.length; i++) {
if (!d.containsKey(KStemData8.data[i])) {
d.put(KStemData8.data[i], defaultEntry);
array = KStemData8.data;
for (String s : array) {
if (!d.containsKey(s)) {
d.put(s, defaultEntry);
} else {
throw new RuntimeException(
"Warning: Entry [" + KStemData8.data[i] + "] already in dictionary 4");
throw new RuntimeException("Warning: Entry [" + s + "] already in dictionary 4");
}
}

for (int i = 0; i < supplementDict.length; i++) {
if (!d.containsKey(supplementDict[i])) {
d.put(supplementDict[i], defaultEntry);
for (String s : supplementDict) {
if (!d.containsKey(s)) {
d.put(s, defaultEntry);
} else {
throw new RuntimeException(
"Warning: Entry [" + supplementDict[i] + "] already in dictionary 5");
throw new RuntimeException("Warning: Entry [" + s + "] already in dictionary 5");
}
}

for (int i = 0; i < properNouns.length; i++) {
if (!d.containsKey(properNouns[i])) {
d.put(properNouns[i], defaultEntry);
for (String properNoun : properNouns) {
if (!d.containsKey(properNoun)) {
d.put(properNoun, defaultEntry);
} else {
throw new RuntimeException(
"Warning: Entry [" + properNouns[i] + "] already in dictionary 6");
throw new RuntimeException("Warning: Entry [" + properNoun + "] already in dictionary 6");
}
}

Expand Down Expand Up @@ -1346,10 +1343,10 @@ private void icEndings() {
return;
}

private static char[] ization = "ization".toCharArray();
private static char[] ition = "ition".toCharArray();
private static char[] ation = "ation".toCharArray();
private static char[] ication = "ication".toCharArray();
private static final char[] ization = "ization".toCharArray();
private static final char[] ition = "ition".toCharArray();
private static final char[] ation = "ation".toCharArray();
private static final char[] ication = "ication".toCharArray();

/* handle some derivational endings */
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ public TokenFilter create(TokenStream input) {
}

// source => type
private static Pattern typePattern = Pattern.compile("(.*)\\s*=>\\s*(.*)\\s*$");
private static final Pattern TYPE_PATTERN = Pattern.compile("(.*)\\s*=>\\s*(.*)\\s*$");

// parses a list of MappingCharFilter style rules into a custom byte[] type table
private byte[] parseTypes(List<String> rules) {
SortedMap<Character, Byte> typeMap = new TreeMap<>();
for (String rule : rules) {
Matcher m = typePattern.matcher(rule);
Matcher m = TYPE_PATTERN.matcher(rule);
if (!m.find()) throw new IllegalArgumentException("Invalid Mapping Rule : [" + rule + "]");
String lhs = parseString(m.group(1).trim());
Byte rhs = parseType(m.group(2).trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ public TokenFilter create(TokenStream input) {
}

// source => type
private static Pattern typePattern = Pattern.compile("(.*)\\s*=>\\s*(.*)\\s*$");
private static final Pattern TYPE_PATTERN = Pattern.compile("(.*)\\s*=>\\s*(.*)\\s*$");

// parses a list of MappingCharFilter style rules into a custom byte[] type table
private byte[] parseTypes(List<String> rules) {
SortedMap<Character, Byte> typeMap = new TreeMap<>();
for (String rule : rules) {
Matcher m = typePattern.matcher(rule);
Matcher m = TYPE_PATTERN.matcher(rule);
if (!m.find()) throw new IllegalArgumentException("Invalid Mapping Rule : [" + rule + "]");
String lhs = parseString(m.group(1).trim());
Byte rhs = parseType(m.group(2).trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum Word2VecSupportedFormats {
DL4J
}

private static Map<String, Word2VecSynonymProvider> word2vecSynonymProviders =
private static final Map<String, Word2VecSynonymProvider> word2vecSynonymProviders =
new ConcurrentHashMap<>();

public static Word2VecSynonymProvider getSynonymProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

/** base class for hunspell stemmer tests */
public abstract class StemmerTestBase extends LuceneTestCase {
@SuppressWarnings("NonFinalStaticField")
private static Stemmer stemmer;

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ public class TestShingleFilter extends BaseTokenStreamTestCase {
public static final String[] UNIGRAM_ONLY_TYPES =
new String[] {"word", "word", "word", "word", "word", "word"};

public static Token[] testTokenWithHoles;
public static final Token[] testTokenWithHoles =
new Token[] {
createToken("please", 0, 6),
createToken("divide", 7, 13),
createToken("sentence", 19, 27, 2),
createToken("shingles", 33, 39, 2),
};

public static final Token[] BI_GRAM_TOKENS =
new Token[] {
Expand Down Expand Up @@ -709,18 +715,6 @@ public class TestShingleFilter extends BaseTokenStreamTestCase {
"shingle", "shingle", "shingle", "shingle",
};

@Override
public void setUp() throws Exception {
super.setUp();
testTokenWithHoles =
new Token[] {
createToken("please", 0, 6),
createToken("divide", 7, 13),
createToken("sentence", 19, 27, 2),
createToken("shingles", 33, 39, 2),
};
}

/*
* Class under test for void ShingleFilter(TokenStream, int)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public class JapaneseIterationMarkCharFilter extends CharFilter {

private static final char FULL_STOP_PUNCTUATION = '\u3002'; // 。

// Hiragana to dakuten map (lookup using code point - 0x30ab(か)*/
private static char[] h2d = new char[50];
// Hiragana to dakuten map (lookup using code point - 0x30ab(か)
private static final char[] h2d = new char[50];

// Katakana to dakuten map (lookup using code point - 0x30ab(カ
private static char[] k2d = new char[50];
// Katakana to dakuten map (lookup using code point - 0x30ab(カ)
private static final char[] k2d = new char[50];

private final RollingCharBuffer buffer = new RollingCharBuffer();

Expand Down
Loading

0 comments on commit ce50d3a

Please sign in to comment.