You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ModifyCollectionInEnhancedForLoop is triggered for ConcurrentMap. While this could be on purpose, as technically ConcurrentHashMap defines the no-throw-ConcurrentModificationException policy, it seems this is accidental in some way as ConcurrentMap is part of java.util.concurrent which is skipped by the check.
Bugs: what's the simplest, easiest way to reproduce this bug?
We have the code:
private final ConcurrentMap<Locality, ClientLoadCounter> localityLoadCounters;
...
for (Map.Entry<Locality, ClientLoadCounter> entry : localityLoadCounters.entrySet()) {
...
localityLoadCounters.remove(entry.getKey());
Which causes a ModifyCollectionInEnhancedForLoop warning:
grpc-java/xds/src/main/java/io/grpc/xds/LoadStatsStoreImpl.java:94: warning: [ModifyCollectionInEnhancedForLoop] Modifying a collection while iterating over it in a loop may cause a ConcurrentModificationException to be thrown or lead to undefined behavior.
localityLoadCounters.remove(entry.getKey());
^
(see https://errorprone.info/bugpattern/ModifyCollectionInEnhancedForLoop)
Swapping from ConcurrentMap to ConcurrentHashMap silences the warning.
Looking at the code, there does not seem to be any ConcurrentMap vs ConcurrentHashMap special-casing, just a large special-case for java.util.concurrent:
…cedForLoop
look at the receive type of an invocation, instead of the type the method
is defined in. E.g. when looking at `map.remove` where `map` is a,
`ConcurrentMap`, we now consider `ConcurrentMap` even though it inherits
`remove` from regular `Map`.
Fixes#1767
PiperOrigin-RevId: 350593573
…cedForLoop
look at the receive type of an invocation, instead of the type the method
is defined in. E.g. when looking at `map.remove` where `map` is a,
`ConcurrentMap`, we now consider `ConcurrentMap` even though it inherits
`remove` from regular `Map`.
Fixesgoogle#1767
PiperOrigin-RevId: 350598002
Description of the problem / feature request:
ModifyCollectionInEnhancedForLoop is triggered for ConcurrentMap. While this could be on purpose, as technically ConcurrentHashMap defines the no-throw-ConcurrentModificationException policy, it seems this is accidental in some way as ConcurrentMap is part of
java.util.concurrent
which is skipped by the check.Bugs: what's the simplest, easiest way to reproduce this bug?
We have the code:
Which causes a ModifyCollectionInEnhancedForLoop warning:
Swapping from ConcurrentMap to ConcurrentHashMap silences the warning.
Looking at the code, there does not seem to be any ConcurrentMap vs ConcurrentHashMap special-casing, just a large special-case for
java.util.concurrent
:error-prone/core/src/main/java/com/google/errorprone/bugpatterns/ModifyCollectionInEnhancedForLoop.java
Lines 76 to 85 in 55a5956
It's unclear how ConcurrentMap triggers the warning.
What version of Error Prone are you using?
2.4.0
Have you found anything relevant by searching the web?
No.
The text was updated successfully, but these errors were encountered: