Skip to content

Commit 2b6b902

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Address a subset of warnings from the likely forthcoming https://errorprone.info/bugpattern/ExposedPrivateType.
And tweak a few other things here and there. PiperOrigin-RevId: 892998863
1 parent 1eb270d commit 2b6b902

23 files changed

Lines changed: 106 additions & 105 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ boolean tryAdvance(Consumer<? super E> action) {
159159
* ordering, if Spliterator.ORDERED is not present).
160160
*/
161161
@IgnoreJRERequirement // *should* be redundant with the annotation on SpliteratorTester
162-
enum SpliteratorDecompositionStrategy {
162+
private enum SpliteratorDecompositionStrategy {
163163
NO_SPLIT_FOR_EACH_REMAINING {
164164
@Override
165165
<E extends @Nullable Object> void forEach(

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,9 @@ public List<Character> create(Character[] elements) {
132132
}
133133
}
134134

135-
private abstract static class TestUnhashableListGenerator
135+
public static class UnhashableElementsImmutableListGenerator
136136
extends TestUnhashableCollectionGenerator<List<UnhashableObject>>
137-
implements TestListGenerator<UnhashableObject> {}
138-
139-
public static class UnhashableElementsImmutableListGenerator extends TestUnhashableListGenerator {
137+
implements TestListGenerator<UnhashableObject> {
140138
@Override
141139
public List<UnhashableObject> create(UnhashableObject[] elements) {
142140
return ImmutableList.copyOf(elements);

android/guava-testlib/test/com/google/common/testing/anotherpackage/ForwardingWrapperTesterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public String toString() {
313313
}
314314
}
315315

316-
public interface Arithmetic extends Adder {
316+
private interface Arithmetic extends Adder {
317317
int minus(int a, int b);
318318
}
319319

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ public Iterable<Tree> apply(Tree node) {
7777
// /|\ |
7878
// / | \ f
7979
// a b c
80-
static final Tree a = new Tree('a');
81-
static final Tree b = new Tree('b');
82-
static final Tree c = new Tree('c');
83-
static final Tree d = new Tree('d', a, b, c);
84-
static final Tree e = new Tree('e');
85-
static final Tree f = new Tree('f');
86-
static final Tree g = new Tree('g', f);
87-
static final Tree h = new Tree('h', d, e, g);
88-
89-
static String iterationOrder(Iterable<? extends Node> iterable) {
80+
private static final Tree a = new Tree('a');
81+
private static final Tree b = new Tree('b');
82+
private static final Tree c = new Tree('c');
83+
private static final Tree d = new Tree('d', a, b, c);
84+
private static final Tree e = new Tree('e');
85+
private static final Tree f = new Tree('f');
86+
private static final Tree g = new Tree('g', f);
87+
private static final Tree h = new Tree('h', d, e, g);
88+
89+
private static String iterationOrder(Iterable<? extends Node> iterable) {
9090
StringBuilder builder = new StringBuilder();
9191
for (Node t : iterable) {
9292
builder.append(t.value);

android/guava/src/com/google/common/cache/CacheBuilderSpec.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ public boolean equals(@Nullable Object obj) {
290290
}
291291

292292
/** Base class for parsing integers. */
293-
abstract static class IntegerParser implements ValueParser {
294-
protected abstract void parseInteger(CacheBuilderSpec spec, int value);
293+
private abstract static class IntegerParser implements ValueParser {
294+
abstract void parseInteger(CacheBuilderSpec spec, int value);
295295

296296
@Override
297297
public void parse(CacheBuilderSpec spec, String key, @Nullable String value) {
@@ -308,8 +308,8 @@ public void parse(CacheBuilderSpec spec, String key, @Nullable String value) {
308308
}
309309

310310
/** Base class for parsing integers. */
311-
abstract static class LongParser implements ValueParser {
312-
protected abstract void parseLong(CacheBuilderSpec spec, long value);
311+
private abstract static class LongParser implements ValueParser {
312+
abstract void parseLong(CacheBuilderSpec spec, long value);
313313

314314
@Override
315315
public void parse(CacheBuilderSpec spec, String key, @Nullable String value) {
@@ -328,7 +328,7 @@ public void parse(CacheBuilderSpec spec, String key, @Nullable String value) {
328328
/** Parse initialCapacity */
329329
private static final class InitialCapacityParser extends IntegerParser {
330330
@Override
331-
protected void parseInteger(CacheBuilderSpec spec, int value) {
331+
void parseInteger(CacheBuilderSpec spec, int value) {
332332
checkArgument(
333333
spec.initialCapacity == null,
334334
"initial capacity was already set to %s",
@@ -340,7 +340,7 @@ protected void parseInteger(CacheBuilderSpec spec, int value) {
340340
/** Parse maximumSize */
341341
private static final class MaximumSizeParser extends LongParser {
342342
@Override
343-
protected void parseLong(CacheBuilderSpec spec, long value) {
343+
void parseLong(CacheBuilderSpec spec, long value) {
344344
checkArgument(
345345
spec.maximumSize == null, "maximum size was already set to %s", spec.maximumSize);
346346
checkArgument(
@@ -352,7 +352,7 @@ protected void parseLong(CacheBuilderSpec spec, long value) {
352352
/** Parse maximumWeight */
353353
private static final class MaximumWeightParser extends LongParser {
354354
@Override
355-
protected void parseLong(CacheBuilderSpec spec, long value) {
355+
void parseLong(CacheBuilderSpec spec, long value) {
356356
checkArgument(
357357
spec.maximumWeight == null, "maximum weight was already set to %s", spec.maximumWeight);
358358
checkArgument(
@@ -364,7 +364,7 @@ protected void parseLong(CacheBuilderSpec spec, long value) {
364364
/** Parse concurrencyLevel */
365365
private static final class ConcurrencyLevelParser extends IntegerParser {
366366
@Override
367-
protected void parseInteger(CacheBuilderSpec spec, int value) {
367+
void parseInteger(CacheBuilderSpec spec, int value) {
368368
checkArgument(
369369
spec.concurrencyLevel == null,
370370
"concurrency level was already set to %s",
@@ -419,8 +419,8 @@ public void parse(CacheBuilderSpec spec, String key, @Nullable String value) {
419419
}
420420

421421
/** Base class for parsing times with durations */
422-
abstract static class DurationParser implements ValueParser {
423-
protected abstract void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit);
422+
private abstract static class DurationParser implements ValueParser {
423+
abstract void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit);
424424

425425
@Override
426426
public void parse(CacheBuilderSpec spec, String key, @Nullable String value) {
@@ -460,7 +460,7 @@ public void parse(CacheBuilderSpec spec, String key, @Nullable String value) {
460460
/** Parse expireAfterAccess */
461461
private static final class AccessDurationParser extends DurationParser {
462462
@Override
463-
protected void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit) {
463+
void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit) {
464464
checkArgument(spec.accessExpirationTimeUnit == null, "expireAfterAccess already set");
465465
spec.accessExpirationDuration = duration;
466466
spec.accessExpirationTimeUnit = unit;
@@ -470,7 +470,7 @@ protected void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit
470470
/** Parse expireAfterWrite */
471471
private static final class WriteDurationParser extends DurationParser {
472472
@Override
473-
protected void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit) {
473+
void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit) {
474474
checkArgument(spec.writeExpirationTimeUnit == null, "expireAfterWrite already set");
475475
spec.writeExpirationDuration = duration;
476476
spec.writeExpirationTimeUnit = unit;
@@ -480,7 +480,7 @@ protected void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit
480480
/** Parse refreshAfterWrite */
481481
private static final class RefreshDurationParser extends DurationParser {
482482
@Override
483-
protected void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit) {
483+
void parseDuration(CacheBuilderSpec spec, long duration, TimeUnit unit) {
484484
checkArgument(spec.refreshTimeUnit == null, "refreshAfterWrite already set");
485485
spec.refreshDuration = duration;
486486
spec.refreshTimeUnit = unit;

android/guava/src/com/google/common/cache/LocalCache.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ public ReferenceEntry<K, V> getNext() {
10031003
}
10041004
}
10051005

1006-
static final class StrongAccessEntry<K, V> extends StrongEntry<K, V> {
1006+
private static final class StrongAccessEntry<K, V> extends StrongEntry<K, V> {
10071007
StrongAccessEntry(K key, int hash, @Nullable ReferenceEntry<K, V> next) {
10081008
super(key, hash, next);
10091009
}
@@ -1049,7 +1049,7 @@ public void setPreviousInAccessQueue(ReferenceEntry<K, V> previous) {
10491049
}
10501050
}
10511051

1052-
static final class StrongWriteEntry<K, V> extends StrongEntry<K, V> {
1052+
private static final class StrongWriteEntry<K, V> extends StrongEntry<K, V> {
10531053
StrongWriteEntry(K key, int hash, @Nullable ReferenceEntry<K, V> next) {
10541054
super(key, hash, next);
10551055
}
@@ -1095,7 +1095,7 @@ public void setPreviousInWriteQueue(ReferenceEntry<K, V> previous) {
10951095
}
10961096
}
10971097

1098-
static final class StrongAccessWriteEntry<K, V> extends StrongEntry<K, V> {
1098+
private static final class StrongAccessWriteEntry<K, V> extends StrongEntry<K, V> {
10991099
StrongAccessWriteEntry(K key, int hash, @Nullable ReferenceEntry<K, V> next) {
11001100
super(key, hash, next);
11011101
}
@@ -1290,7 +1290,7 @@ public ReferenceEntry<K, V> getNext() {
12901290
}
12911291
}
12921292

1293-
static final class WeakAccessEntry<K, V> extends WeakEntry<K, V> {
1293+
private static final class WeakAccessEntry<K, V> extends WeakEntry<K, V> {
12941294
WeakAccessEntry(ReferenceQueue<K> queue, K key, int hash, @Nullable ReferenceEntry<K, V> next) {
12951295
super(queue, key, hash, next);
12961296
}
@@ -1336,7 +1336,7 @@ public void setPreviousInAccessQueue(ReferenceEntry<K, V> previous) {
13361336
}
13371337
}
13381338

1339-
static final class WeakWriteEntry<K, V> extends WeakEntry<K, V> {
1339+
private static final class WeakWriteEntry<K, V> extends WeakEntry<K, V> {
13401340
WeakWriteEntry(ReferenceQueue<K> queue, K key, int hash, @Nullable ReferenceEntry<K, V> next) {
13411341
super(queue, key, hash, next);
13421342
}
@@ -1382,7 +1382,7 @@ public void setPreviousInWriteQueue(ReferenceEntry<K, V> previous) {
13821382
}
13831383
}
13841384

1385-
static final class WeakAccessWriteEntry<K, V> extends WeakEntry<K, V> {
1385+
private static final class WeakAccessWriteEntry<K, V> extends WeakEntry<K, V> {
13861386
WeakAccessWriteEntry(
13871387
ReferenceQueue<K> queue, K key, int hash, @Nullable ReferenceEntry<K, V> next) {
13881388
super(queue, key, hash, next);
@@ -1608,7 +1608,7 @@ public void notifyNewValue(V newValue) {}
16081608
}
16091609

16101610
/** References a weak value. */
1611-
static final class WeightedWeakValueReference<K, V> extends WeakValueReference<K, V> {
1611+
private static final class WeightedWeakValueReference<K, V> extends WeakValueReference<K, V> {
16121612
final int weight;
16131613

16141614
WeightedWeakValueReference(
@@ -1630,7 +1630,7 @@ public ValueReference<K, V> copyFor(
16301630
}
16311631

16321632
/** References a soft value. */
1633-
static final class WeightedSoftValueReference<K, V> extends SoftValueReference<K, V> {
1633+
private static final class WeightedSoftValueReference<K, V> extends SoftValueReference<K, V> {
16341634
final int weight;
16351635

16361636
WeightedSoftValueReference(
@@ -1652,7 +1652,7 @@ public ValueReference<K, V> copyFor(
16521652
}
16531653

16541654
/** References a strong value. */
1655-
static final class WeightedStrongValueReference<K, V> extends StrongValueReference<K, V> {
1655+
private static final class WeightedStrongValueReference<K, V> extends StrongValueReference<K, V> {
16561656
final int weight;
16571657

16581658
WeightedStrongValueReference(V referent, int weight) {
@@ -4611,7 +4611,7 @@ protected Cache<K, V> delegate() {
46114611
* <p>Unfortunately, readResolve() doesn't get called when a circular dependency is present, so
46124612
* the proxy must be able to behave as the cache itself.
46134613
*/
4614-
static final class LoadingSerializationProxy<K, V> extends ManualSerializationProxy<K, V>
4614+
private static final class LoadingSerializationProxy<K, V> extends ManualSerializationProxy<K, V>
46154615
implements LoadingCache<K, V> {
46164616
@GwtIncompatible @J2ktIncompatible private static final long serialVersionUID = 1;
46174617

android/guava/src/com/google/common/collect/MapMakerInternalMap.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,7 +2122,7 @@ StrongKeyDummyValueSegment<K> self() {
21222122

21232123
@SuppressWarnings("unchecked")
21242124
@Override
2125-
public StrongKeyDummyValueEntry<K> castForTesting(InternalEntry<K, Dummy, ?> entry) {
2125+
StrongKeyDummyValueEntry<K> castForTesting(InternalEntry<K, Dummy, ?> entry) {
21262126
return (StrongKeyDummyValueEntry<K>) entry;
21272127
}
21282128
}
@@ -2195,19 +2195,18 @@ ReferenceQueue<V> getValueReferenceQueueForTesting() {
21952195

21962196
@SuppressWarnings("unchecked")
21972197
@Override
2198-
public @Nullable WeakKeyWeakValueEntry<K, V> castForTesting(
2199-
@Nullable InternalEntry<K, V, ?> entry) {
2198+
@Nullable WeakKeyWeakValueEntry<K, V> castForTesting(@Nullable InternalEntry<K, V, ?> entry) {
22002199
return (WeakKeyWeakValueEntry<K, V>) entry;
22012200
}
22022201

22032202
@Override
2204-
public WeakValueReference<K, V, WeakKeyWeakValueEntry<K, V>> getWeakValueReferenceForTesting(
2203+
WeakValueReference<K, V, WeakKeyWeakValueEntry<K, V>> getWeakValueReferenceForTesting(
22052204
InternalEntry<K, V, ?> e) {
22062205
return castForTesting(e).getValueReference();
22072206
}
22082207

22092208
@Override
2210-
public WeakValueReference<K, V, WeakKeyWeakValueEntry<K, V>> newWeakValueReferenceForTesting(
2209+
WeakValueReference<K, V, WeakKeyWeakValueEntry<K, V>> newWeakValueReferenceForTesting(
22112210
InternalEntry<K, V, ?> e, V value) {
22122211
return new WeakValueReferenceImpl<>(queueForValues, value, castForTesting(e));
22132212
}
@@ -2260,7 +2259,7 @@ ReferenceQueue<K> getKeyReferenceQueueForTesting() {
22602259

22612260
@SuppressWarnings("unchecked")
22622261
@Override
2263-
public WeakKeyDummyValueEntry<K> castForTesting(InternalEntry<K, Dummy, ?> entry) {
2262+
WeakKeyDummyValueEntry<K> castForTesting(InternalEntry<K, Dummy, ?> entry) {
22642263
return (WeakKeyDummyValueEntry<K>) entry;
22652264
}
22662265

android/guava/src/com/google/common/collect/Maps.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3214,7 +3214,8 @@ public NavigableMap<K, V> tailMap(@ParametricNullness K fromKey, boolean inclusi
32143214
}
32153215
}
32163216

3217-
static final class FilteredEntryBiMap<K extends @Nullable Object, V extends @Nullable Object>
3217+
private static final class FilteredEntryBiMap<
3218+
K extends @Nullable Object, V extends @Nullable Object>
32183219
extends FilteredEntryMap<K, V> implements BiMap<K, V> {
32193220
@RetainedWith private final BiMap<V, K> inverse;
32203221

android/guava/src/com/google/common/hash/LittleEndianByteArray.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ static boolean usingFastPath() {
123123
* <p>This abstraction allows us to use single-instruction load and put when available, or fall
124124
* back on the slower approach of using Longs.fromBytes(byte...).
125125
*/
126-
private interface LittleEndianBytes {
126+
@VisibleForTesting
127+
interface LittleEndianBytes {
127128
long getLongLittleEndian(byte[] array, int offset);
128129

129130
void putLongLittleEndian(byte[] array, int offset, long value);
@@ -254,7 +255,7 @@ public boolean usesFastPath() {
254255
}
255256
}
256257

257-
static LittleEndianBytes makeGetter() {
258+
private static LittleEndianBytes makeGetter() {
258259
try {
259260
/*
260261
* UnsafeByteArray uses Unsafe.getLong() in an unsupported way, which is known to cause

android/guava/src/com/google/common/util/concurrent/ClosingFuture.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public final class ClosingFuture<V extends @Nullable Object> {
211211
public static final class DeferredCloser {
212212
@RetainedWith private final CloseableList list;
213213

214-
DeferredCloser(CloseableList list) {
214+
private DeferredCloser(CloseableList list) {
215215
this.list = list;
216216
}
217217

@@ -326,7 +326,7 @@ public static final class ValueAndCloser<V extends @Nullable Object> {
326326

327327
private final State<? extends V> state;
328328

329-
ValueAndCloser(State<? extends V> state) {
329+
private ValueAndCloser(State<? extends V> state) {
330330
this.state = state;
331331
}
332332

0 commit comments

Comments
 (0)