Skip to content

Commit dc12fb2

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Address [InitializeInline](https://errorprone.info/bugpattern/InitializeInline) warnings.
PiperOrigin-RevId: 687386859
1 parent f5108a3 commit dc12fb2

File tree

8 files changed

+24
-48
lines changed

8 files changed

+24
-48
lines changed

android/guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,14 @@ public void testContainsValue() {
337337

338338
public void testEntrySet() {
339339
Map<K, V> map;
340-
Set<Entry<K, V>> entrySet;
341340
try {
342341
map = makePopulatedMap();
343342
} catch (UnsupportedOperationException e) {
344343
return;
345344
}
346345
assertInvariants(map);
347346

348-
entrySet = map.entrySet();
347+
Set<Entry<K, V>> entrySet = map.entrySet();
349348
K unmappedKey;
350349
V unmappedValue;
351350
try {
@@ -373,15 +372,14 @@ public void testEntrySetForEmptyMap() {
373372
@J2ktIncompatible // https://youtrack.jetbrains.com/issue/KT-58242/ undefined behavior (crash)
374373
public void testEntrySetContainsEntryIncompatibleKey() {
375374
Map<K, V> map;
376-
Set<Entry<K, V>> entrySet;
377375
try {
378376
map = makeEitherMap();
379377
} catch (UnsupportedOperationException e) {
380378
return;
381379
}
382380
assertInvariants(map);
383381

384-
entrySet = map.entrySet();
382+
Set<Entry<K, V>> entrySet = map.entrySet();
385383
V unmappedValue;
386384
try {
387385
unmappedValue = getValueNotInPopulatedMap();
@@ -400,15 +398,14 @@ public void testEntrySetContainsEntryNullKeyPresent() {
400398
return;
401399
}
402400
Map<K, V> map;
403-
Set<Entry<K, V>> entrySet;
404401
try {
405402
map = makeEitherMap();
406403
} catch (UnsupportedOperationException e) {
407404
return;
408405
}
409406
assertInvariants(map);
410407

411-
entrySet = map.entrySet();
408+
Set<Entry<K, V>> entrySet = map.entrySet();
412409
V unmappedValue;
413410
try {
414411
unmappedValue = getValueNotInPopulatedMap();
@@ -425,15 +422,14 @@ public void testEntrySetContainsEntryNullKeyPresent() {
425422

426423
public void testEntrySetContainsEntryNullKeyMissing() {
427424
Map<K, V> map;
428-
Set<Entry<K, V>> entrySet;
429425
try {
430426
map = makeEitherMap();
431427
} catch (UnsupportedOperationException e) {
432428
return;
433429
}
434430
assertInvariants(map);
435431

436-
entrySet = map.entrySet();
432+
Set<Entry<K, V>> entrySet = map.entrySet();
437433
V unmappedValue;
438434
try {
439435
unmappedValue = getValueNotInPopulatedMap();
@@ -565,15 +561,14 @@ public void testEntrySetRemoveNullKeyPresent() {
565561
return;
566562
}
567563
Map<K, V> map;
568-
Set<Entry<K, V>> entrySet;
569564
try {
570565
map = makeEitherMap();
571566
} catch (UnsupportedOperationException e) {
572567
return;
573568
}
574569
assertInvariants(map);
575570

576-
entrySet = map.entrySet();
571+
Set<Entry<K, V>> entrySet = map.entrySet();
577572
V unmappedValue;
578573
try {
579574
unmappedValue = getValueNotInPopulatedMap();
@@ -979,15 +974,14 @@ public void testPutNewKey() {
979974

980975
public void testPutExistingKey() {
981976
Map<K, V> map;
982-
K keyToPut;
983977
V valueToPut;
984978
try {
985979
map = makePopulatedMap();
986980
valueToPut = getValueNotInPopulatedMap();
987981
} catch (UnsupportedOperationException e) {
988982
return;
989983
}
990-
keyToPut = map.keySet().iterator().next();
984+
K keyToPut = map.keySet().iterator().next();
991985
if (supportsPut) {
992986
int initialSize = map.size();
993987
map.put(keyToPut, valueToPut);
@@ -1104,15 +1098,14 @@ public void testPutAllNewKey() {
11041098

11051099
public void testPutAllExistingKey() {
11061100
Map<K, V> map;
1107-
K keyToPut;
11081101
V valueToPut;
11091102
try {
11101103
map = makePopulatedMap();
11111104
valueToPut = getValueNotInPopulatedMap();
11121105
} catch (UnsupportedOperationException e) {
11131106
return;
11141107
}
1115-
keyToPut = map.keySet().iterator().next();
1108+
K keyToPut = map.keySet().iterator().next();
11161109
Map<K, V> mapToPut = Collections.singletonMap(keyToPut, valueToPut);
11171110
int initialSize = map.size();
11181111
if (supportsPut) {
@@ -1129,13 +1122,12 @@ public void testPutAllExistingKey() {
11291122

11301123
public void testRemove() {
11311124
Map<K, V> map;
1132-
K keyToRemove;
11331125
try {
11341126
map = makePopulatedMap();
11351127
} catch (UnsupportedOperationException e) {
11361128
return;
11371129
}
1138-
keyToRemove = map.keySet().iterator().next();
1130+
K keyToRemove = map.keySet().iterator().next();
11391131
if (supportsRemove) {
11401132
int initialSize = map.size();
11411133
V expectedValue = map.get(keyToRemove);
@@ -1304,15 +1296,14 @@ public void testKeySetRetainAllNullFromEmpty() {
13041296

13051297
public void testValues() {
13061298
Map<K, V> map;
1307-
Collection<V> valueCollection;
13081299
try {
13091300
map = makePopulatedMap();
13101301
} catch (UnsupportedOperationException e) {
13111302
return;
13121303
}
13131304
assertInvariants(map);
13141305

1315-
valueCollection = map.values();
1306+
Collection<V> valueCollection = map.values();
13161307
V unmappedValue;
13171308
try {
13181309
unmappedValue = getValueNotInPopulatedMap();

android/guava-tests/test/com/google/common/collect/AbstractMultimapAsMapImplementsMapTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,12 @@ protected Collection<Integer> getValueNotInPopulatedMap() throws UnsupportedOper
6767
@Override
6868
public void testRemove() {
6969
final Map<String, Collection<Integer>> map;
70-
final String keyToRemove;
7170
try {
7271
map = makePopulatedMap();
7372
} catch (UnsupportedOperationException e) {
7473
return;
7574
}
76-
keyToRemove = map.keySet().iterator().next();
75+
final String keyToRemove = map.keySet().iterator().next();
7776
if (supportsRemove) {
7877
int initialSize = map.size();
7978
map.get(keyToRemove);

android/guava-tests/test/com/google/common/collect/TableCollectionTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,13 +838,12 @@ protected Map<Integer, Character> getValueNotInPopulatedMap() {
838838
@Override
839839
public void testRemove() {
840840
final Map<String, Map<Integer, Character>> map;
841-
final String keyToRemove;
842841
try {
843842
map = makePopulatedMap();
844843
} catch (UnsupportedOperationException e) {
845844
return;
846845
}
847-
keyToRemove = map.keySet().iterator().next();
846+
final String keyToRemove = map.keySet().iterator().next();
848847
if (supportsRemove) {
849848
int initialSize = map.size();
850849
map.get(keyToRemove);

android/guava-tests/test/com/google/common/hash/Murmur3Hash32Test.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ public void testSimpleStringUtf8() {
115115
public void testEncodedStringInputs() {
116116
Random rng = new Random(0);
117117
for (int z = 0; z < 100; z++) {
118-
String str;
119118
int[] codePoints = new int[rng.nextInt(8)];
120119
for (int i = 0; i < codePoints.length; i++) {
121120
do {
@@ -128,7 +127,7 @@ public void testEncodedStringInputs() {
128127
for (int i = 0; i < codePoints.length; i++) {
129128
builder.appendCodePoint(codePoints[i]);
130129
}
131-
str = builder.toString();
130+
String str = builder.toString();
132131
HashCode hashUtf8 = murmur3_32().hashBytes(str.getBytes(UTF_8));
133132
assertEquals(hashUtf8, murmur3_32().newHasher().putBytes(str.getBytes(UTF_8)).hash());
134133
assertEquals(hashUtf8, murmur3_32().hashString(str, UTF_8));

guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,14 @@ public void testContainsValue() {
337337

338338
public void testEntrySet() {
339339
Map<K, V> map;
340-
Set<Entry<K, V>> entrySet;
341340
try {
342341
map = makePopulatedMap();
343342
} catch (UnsupportedOperationException e) {
344343
return;
345344
}
346345
assertInvariants(map);
347346

348-
entrySet = map.entrySet();
347+
Set<Entry<K, V>> entrySet = map.entrySet();
349348
K unmappedKey;
350349
V unmappedValue;
351350
try {
@@ -373,15 +372,14 @@ public void testEntrySetForEmptyMap() {
373372
@J2ktIncompatible // https://youtrack.jetbrains.com/issue/KT-58242/ undefined behavior (crash)
374373
public void testEntrySetContainsEntryIncompatibleKey() {
375374
Map<K, V> map;
376-
Set<Entry<K, V>> entrySet;
377375
try {
378376
map = makeEitherMap();
379377
} catch (UnsupportedOperationException e) {
380378
return;
381379
}
382380
assertInvariants(map);
383381

384-
entrySet = map.entrySet();
382+
Set<Entry<K, V>> entrySet = map.entrySet();
385383
V unmappedValue;
386384
try {
387385
unmappedValue = getValueNotInPopulatedMap();
@@ -400,15 +398,14 @@ public void testEntrySetContainsEntryNullKeyPresent() {
400398
return;
401399
}
402400
Map<K, V> map;
403-
Set<Entry<K, V>> entrySet;
404401
try {
405402
map = makeEitherMap();
406403
} catch (UnsupportedOperationException e) {
407404
return;
408405
}
409406
assertInvariants(map);
410407

411-
entrySet = map.entrySet();
408+
Set<Entry<K, V>> entrySet = map.entrySet();
412409
V unmappedValue;
413410
try {
414411
unmappedValue = getValueNotInPopulatedMap();
@@ -425,15 +422,14 @@ public void testEntrySetContainsEntryNullKeyPresent() {
425422

426423
public void testEntrySetContainsEntryNullKeyMissing() {
427424
Map<K, V> map;
428-
Set<Entry<K, V>> entrySet;
429425
try {
430426
map = makeEitherMap();
431427
} catch (UnsupportedOperationException e) {
432428
return;
433429
}
434430
assertInvariants(map);
435431

436-
entrySet = map.entrySet();
432+
Set<Entry<K, V>> entrySet = map.entrySet();
437433
V unmappedValue;
438434
try {
439435
unmappedValue = getValueNotInPopulatedMap();
@@ -565,15 +561,14 @@ public void testEntrySetRemoveNullKeyPresent() {
565561
return;
566562
}
567563
Map<K, V> map;
568-
Set<Entry<K, V>> entrySet;
569564
try {
570565
map = makeEitherMap();
571566
} catch (UnsupportedOperationException e) {
572567
return;
573568
}
574569
assertInvariants(map);
575570

576-
entrySet = map.entrySet();
571+
Set<Entry<K, V>> entrySet = map.entrySet();
577572
V unmappedValue;
578573
try {
579574
unmappedValue = getValueNotInPopulatedMap();
@@ -979,15 +974,14 @@ public void testPutNewKey() {
979974

980975
public void testPutExistingKey() {
981976
Map<K, V> map;
982-
K keyToPut;
983977
V valueToPut;
984978
try {
985979
map = makePopulatedMap();
986980
valueToPut = getValueNotInPopulatedMap();
987981
} catch (UnsupportedOperationException e) {
988982
return;
989983
}
990-
keyToPut = map.keySet().iterator().next();
984+
K keyToPut = map.keySet().iterator().next();
991985
if (supportsPut) {
992986
int initialSize = map.size();
993987
map.put(keyToPut, valueToPut);
@@ -1104,15 +1098,14 @@ public void testPutAllNewKey() {
11041098

11051099
public void testPutAllExistingKey() {
11061100
Map<K, V> map;
1107-
K keyToPut;
11081101
V valueToPut;
11091102
try {
11101103
map = makePopulatedMap();
11111104
valueToPut = getValueNotInPopulatedMap();
11121105
} catch (UnsupportedOperationException e) {
11131106
return;
11141107
}
1115-
keyToPut = map.keySet().iterator().next();
1108+
K keyToPut = map.keySet().iterator().next();
11161109
Map<K, V> mapToPut = Collections.singletonMap(keyToPut, valueToPut);
11171110
int initialSize = map.size();
11181111
if (supportsPut) {
@@ -1129,13 +1122,12 @@ public void testPutAllExistingKey() {
11291122

11301123
public void testRemove() {
11311124
Map<K, V> map;
1132-
K keyToRemove;
11331125
try {
11341126
map = makePopulatedMap();
11351127
} catch (UnsupportedOperationException e) {
11361128
return;
11371129
}
1138-
keyToRemove = map.keySet().iterator().next();
1130+
K keyToRemove = map.keySet().iterator().next();
11391131
if (supportsRemove) {
11401132
int initialSize = map.size();
11411133
V expectedValue = map.get(keyToRemove);
@@ -1304,15 +1296,14 @@ public void testKeySetRetainAllNullFromEmpty() {
13041296

13051297
public void testValues() {
13061298
Map<K, V> map;
1307-
Collection<V> valueCollection;
13081299
try {
13091300
map = makePopulatedMap();
13101301
} catch (UnsupportedOperationException e) {
13111302
return;
13121303
}
13131304
assertInvariants(map);
13141305

1315-
valueCollection = map.values();
1306+
Collection<V> valueCollection = map.values();
13161307
V unmappedValue;
13171308
try {
13181309
unmappedValue = getValueNotInPopulatedMap();

guava-tests/test/com/google/common/collect/AbstractMultimapAsMapImplementsMapTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,12 @@ protected Collection<Integer> getValueNotInPopulatedMap() throws UnsupportedOper
6767
@Override
6868
public void testRemove() {
6969
final Map<String, Collection<Integer>> map;
70-
final String keyToRemove;
7170
try {
7271
map = makePopulatedMap();
7372
} catch (UnsupportedOperationException e) {
7473
return;
7574
}
76-
keyToRemove = map.keySet().iterator().next();
75+
final String keyToRemove = map.keySet().iterator().next();
7776
if (supportsRemove) {
7877
int initialSize = map.size();
7978
map.get(keyToRemove);

guava-tests/test/com/google/common/collect/TableCollectionTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,13 +838,12 @@ protected Map<Integer, Character> getValueNotInPopulatedMap() {
838838
@Override
839839
public void testRemove() {
840840
final Map<String, Map<Integer, Character>> map;
841-
final String keyToRemove;
842841
try {
843842
map = makePopulatedMap();
844843
} catch (UnsupportedOperationException e) {
845844
return;
846845
}
847-
keyToRemove = map.keySet().iterator().next();
846+
final String keyToRemove = map.keySet().iterator().next();
848847
if (supportsRemove) {
849848
int initialSize = map.size();
850849
map.get(keyToRemove);

guava-tests/test/com/google/common/hash/Murmur3Hash32Test.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ public void testSimpleStringUtf8() {
115115
public void testEncodedStringInputs() {
116116
Random rng = new Random(0);
117117
for (int z = 0; z < 100; z++) {
118-
String str;
119118
int[] codePoints = new int[rng.nextInt(8)];
120119
for (int i = 0; i < codePoints.length; i++) {
121120
do {
@@ -128,7 +127,7 @@ public void testEncodedStringInputs() {
128127
for (int i = 0; i < codePoints.length; i++) {
129128
builder.appendCodePoint(codePoints[i]);
130129
}
131-
str = builder.toString();
130+
String str = builder.toString();
132131
HashCode hashUtf8 = murmur3_32().hashBytes(str.getBytes(UTF_8));
133132
assertEquals(hashUtf8, murmur3_32().newHasher().putBytes(str.getBytes(UTF_8)).hash());
134133
assertEquals(hashUtf8, murmur3_32().hashString(str, UTF_8));

0 commit comments

Comments
 (0)