Skip to content

Commit 2de2021

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Address a few Error Prone warnings.
RELNOTES=n/a PiperOrigin-RevId: 805883202
1 parent ce75979 commit 2de2021

File tree

11 files changed

+32
-50
lines changed

11 files changed

+32
-50
lines changed

android/guava/src/com/google/common/eventbus/SubscriberExceptionContext.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,24 @@ public class SubscriberExceptionContext {
4545
}
4646

4747
/**
48-
* @return The {@link EventBus} that handled the event and the subscriber. Useful for broadcasting
49-
* a new event based on the error.
48+
* Returns the {@link EventBus} that handled the event and the subscriber. Useful for broadcasting
49+
* a new event based on the error.
5050
*/
5151
public EventBus getEventBus() {
5252
return eventBus;
5353
}
5454

55-
/**
56-
* @return The event object that caused the subscriber to throw.
57-
*/
55+
/** Returns the event object that caused the subscriber to throw. */
5856
public Object getEvent() {
5957
return event;
6058
}
6159

62-
/**
63-
* @return The object context that the subscriber was called on.
64-
*/
60+
/** Returns the object context that the subscriber was called on. */
6561
public Object getSubscriber() {
6662
return subscriber;
6763
}
6864

69-
/**
70-
* @return The subscribed method that threw the exception.
71-
*/
65+
/** Returns the subscribed method that threw the exception. */
7266
public Method getSubscriberMethod() {
7367
return subscriberMethod;
7468
}

android/guava/src/com/google/common/math/IntMath.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,10 @@ public static int checkedPow(int b, int k) {
517517
case 0:
518518
return accum;
519519
case 1:
520-
return checkedMultiply(accum, b);
520+
return Math.multiplyExact(accum, b);
521521
default:
522522
if ((k & 1) != 0) {
523-
accum = checkedMultiply(accum, b);
523+
accum = Math.multiplyExact(accum, b);
524524
}
525525
k >>= 1;
526526
if (k > 0) {

android/guava/src/com/google/common/math/LongMath.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,10 @@ public static long checkedPow(long b, int k) {
615615
case 0:
616616
return accum;
617617
case 1:
618-
return checkedMultiply(accum, b);
618+
return Math.multiplyExact(accum, b);
619619
default:
620620
if ((k & 1) != 0) {
621-
accum = checkedMultiply(accum, b);
621+
accum = Math.multiplyExact(accum, b);
622622
}
623623
k >>= 1;
624624
if (k > 0) {

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.google.common.util.concurrent;
1616

1717
import static com.google.common.base.Preconditions.checkNotNull;
18+
import static com.google.common.collect.Lists.newArrayListWithCapacity;
1819
import static java.util.Objects.requireNonNull;
1920

2021
import com.google.common.annotations.GwtIncompatible;
@@ -459,11 +460,11 @@ private CycleDetectingLockFactory(Policy policy) {
459460
*/
460461
// This is logically a Set, but an ArrayList is used to minimize the amount
461462
// of allocation done on lock()/unlock().
462-
private static final ThreadLocal<ArrayList<LockGraphNode>> acquiredLocks =
463-
new ThreadLocal<ArrayList<LockGraphNode>>() {
463+
private static final ThreadLocal<List<LockGraphNode>> acquiredLocks =
464+
new ThreadLocal<List<LockGraphNode>>() {
464465
@Override
465-
protected ArrayList<LockGraphNode> initialValue() {
466-
return Lists.<LockGraphNode>newArrayListWithCapacity(3);
466+
protected List<LockGraphNode> initialValue() {
467+
return newArrayListWithCapacity(3);
467468
}
468469
};
469470

@@ -713,7 +714,7 @@ void checkAcquiredLock(Policy policy, LockGraphNode acquiredLock) {
713714
private void aboutToAcquire(CycleDetectingLock lock) {
714715
if (!lock.isAcquiredByCurrentThread()) {
715716
// requireNonNull accommodates Android's @RecentlyNullable annotation on ThreadLocal.get
716-
ArrayList<LockGraphNode> acquiredLockList = requireNonNull(acquiredLocks.get());
717+
List<LockGraphNode> acquiredLockList = requireNonNull(acquiredLocks.get());
717718
LockGraphNode node = lock.getLockGraphNode();
718719
node.checkAcquiredLocks(policy, acquiredLockList);
719720
acquiredLockList.add(node);
@@ -728,7 +729,7 @@ private void aboutToAcquire(CycleDetectingLock lock) {
728729
private static void lockStateChanged(CycleDetectingLock lock) {
729730
if (!lock.isAcquiredByCurrentThread()) {
730731
// requireNonNull accommodates Android's @RecentlyNullable annotation on ThreadLocal.get
731-
ArrayList<LockGraphNode> acquiredLockList = requireNonNull(acquiredLocks.get());
732+
List<LockGraphNode> acquiredLockList = requireNonNull(acquiredLocks.get());
732733
LockGraphNode node = lock.getLockGraphNode();
733734
// Iterate in reverse because locks are usually locked/unlocked in a
734735
// LIFO order.

android/guava/src/com/google/common/xml/XmlEscapers.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ public static Escaper xmlContentEscaper() {
9797
public static Escaper xmlAttributeEscaper() {
9898
return XML_ATTRIBUTE_ESCAPER;
9999
}
100-
101-
private static final Escaper XML_ESCAPER;
102100
private static final Escaper XML_CONTENT_ESCAPER;
103101
private static final Escaper XML_ATTRIBUTE_ESCAPER;
104102

@@ -134,7 +132,6 @@ public static Escaper xmlAttributeEscaper() {
134132
XML_CONTENT_ESCAPER = builder.build();
135133
builder.addEscape('\'', "&apos;");
136134
builder.addEscape('"', "&quot;");
137-
XML_ESCAPER = builder.build();
138135
builder.addEscape('\t', "&#x9;");
139136
builder.addEscape('\n', "&#xA;");
140137
builder.addEscape('\r', "&#xD;");

guava/src/com/google/common/base/Platform.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.google.common.annotations.GwtCompatible;
1919
import java.lang.ref.WeakReference;
2020
import java.util.Locale;
21-
import java.util.logging.Logger;
2221
import java.util.regex.Pattern;
2322
import org.jspecify.annotations.Nullable;
2423

@@ -29,7 +28,6 @@
2928
*/
3029
@GwtCompatible
3130
final class Platform {
32-
private static final Logger logger = Logger.getLogger(Platform.class.getName());
3331
private static final PatternCompiler patternCompiler = loadPatternCompiler();
3432

3533
private Platform() {}

guava/src/com/google/common/eventbus/SubscriberExceptionContext.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,24 @@ public class SubscriberExceptionContext {
4545
}
4646

4747
/**
48-
* @return The {@link EventBus} that handled the event and the subscriber. Useful for broadcasting
49-
* a new event based on the error.
48+
* Returns the {@link EventBus} that handled the event and the subscriber. Useful for broadcasting
49+
* a new event based on the error.
5050
*/
5151
public EventBus getEventBus() {
5252
return eventBus;
5353
}
5454

55-
/**
56-
* @return The event object that caused the subscriber to throw.
57-
*/
55+
/** Returns the event object that caused the subscriber to throw. */
5856
public Object getEvent() {
5957
return event;
6058
}
6159

62-
/**
63-
* @return The object context that the subscriber was called on.
64-
*/
60+
/** Returns the object context that the subscriber was called on. */
6561
public Object getSubscriber() {
6662
return subscriber;
6763
}
6864

69-
/**
70-
* @return The subscribed method that threw the exception.
71-
*/
65+
/** Returns the subscribed method that threw the exception. */
7266
public Method getSubscriberMethod() {
7367
return subscriberMethod;
7468
}

guava/src/com/google/common/math/IntMath.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,10 @@ public static int checkedPow(int b, int k) {
517517
case 0:
518518
return accum;
519519
case 1:
520-
return checkedMultiply(accum, b);
520+
return Math.multiplyExact(accum, b);
521521
default:
522522
if ((k & 1) != 0) {
523-
accum = checkedMultiply(accum, b);
523+
accum = Math.multiplyExact(accum, b);
524524
}
525525
k >>= 1;
526526
if (k > 0) {

guava/src/com/google/common/math/LongMath.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,10 @@ public static long checkedPow(long b, int k) {
615615
case 0:
616616
return accum;
617617
case 1:
618-
return checkedMultiply(accum, b);
618+
return Math.multiplyExact(accum, b);
619619
default:
620620
if ((k & 1) != 0) {
621-
accum = checkedMultiply(accum, b);
621+
accum = Math.multiplyExact(accum, b);
622622
}
623623
k >>= 1;
624624
if (k > 0) {

guava/src/com/google/common/util/concurrent/CycleDetectingLockFactory.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.google.common.util.concurrent;
1616

1717
import static com.google.common.base.Preconditions.checkNotNull;
18+
import static com.google.common.collect.Lists.newArrayListWithCapacity;
1819
import static java.util.Objects.requireNonNull;
1920

2021
import com.google.common.annotations.GwtIncompatible;
@@ -459,11 +460,11 @@ private CycleDetectingLockFactory(Policy policy) {
459460
*/
460461
// This is logically a Set, but an ArrayList is used to minimize the amount
461462
// of allocation done on lock()/unlock().
462-
private static final ThreadLocal<ArrayList<LockGraphNode>> acquiredLocks =
463-
new ThreadLocal<ArrayList<LockGraphNode>>() {
463+
private static final ThreadLocal<List<LockGraphNode>> acquiredLocks =
464+
new ThreadLocal<List<LockGraphNode>>() {
464465
@Override
465-
protected ArrayList<LockGraphNode> initialValue() {
466-
return Lists.<LockGraphNode>newArrayListWithCapacity(3);
466+
protected List<LockGraphNode> initialValue() {
467+
return newArrayListWithCapacity(3);
467468
}
468469
};
469470

@@ -713,7 +714,7 @@ void checkAcquiredLock(Policy policy, LockGraphNode acquiredLock) {
713714
private void aboutToAcquire(CycleDetectingLock lock) {
714715
if (!lock.isAcquiredByCurrentThread()) {
715716
// requireNonNull accommodates Android's @RecentlyNullable annotation on ThreadLocal.get
716-
ArrayList<LockGraphNode> acquiredLockList = requireNonNull(acquiredLocks.get());
717+
List<LockGraphNode> acquiredLockList = requireNonNull(acquiredLocks.get());
717718
LockGraphNode node = lock.getLockGraphNode();
718719
node.checkAcquiredLocks(policy, acquiredLockList);
719720
acquiredLockList.add(node);
@@ -728,7 +729,7 @@ private void aboutToAcquire(CycleDetectingLock lock) {
728729
private static void lockStateChanged(CycleDetectingLock lock) {
729730
if (!lock.isAcquiredByCurrentThread()) {
730731
// requireNonNull accommodates Android's @RecentlyNullable annotation on ThreadLocal.get
731-
ArrayList<LockGraphNode> acquiredLockList = requireNonNull(acquiredLocks.get());
732+
List<LockGraphNode> acquiredLockList = requireNonNull(acquiredLocks.get());
732733
LockGraphNode node = lock.getLockGraphNode();
733734
// Iterate in reverse because locks are usually locked/unlocked in a
734735
// LIFO order.

0 commit comments

Comments
 (0)