summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2023-09-21 12:06:02 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2023-09-25 22:05:14 +0200
commitd5bcf199c7650829850689fb5e8b7172ec5ab5ee (patch)
tree7070e3a8c999b32c3978f5f315806ea82b69ba65
parent8302377d913ccd344318ea3996e7106469ae4940 (diff)
downloadjgit-d5bcf199c7650829850689fb5e8b7172ec5ab5ee.tar.gz
jgit-d5bcf199c7650829850689fb5e8b7172ec5ab5ee.zip
[errorprone] Transport: Suppress ModifyCollectionInEnhancedForLoop
CopyOnWriteArrayList is thread-safe. See https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/CopyOnWriteArrayList.html https://errorprone.info/bugpattern/ModifyCollectionInEnhancedForLoop Change-Id: I97c411e7d171cb39a9c0676b076d48103db6ff88
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
index 4d2f4a9ac0..271f462aa6 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
@@ -191,11 +191,13 @@ public abstract class Transport implements AutoCloseable {
* @param proto
* the exact object previously given to register.
*/
+ @SuppressWarnings("ModifyCollectionInEnhancedForLoop")
public static void unregister(TransportProtocol proto) {
for (WeakReference<TransportProtocol> ref : protocols) {
TransportProtocol refProto = ref.get();
- if (refProto == null || refProto == proto)
+ if (refProto == null || refProto == proto) {
protocols.remove(ref);
+ }
}
}
@@ -204,15 +206,17 @@ public abstract class Transport implements AutoCloseable {
*
* @return an immutable copy of the currently registered protocols.
*/
+ @SuppressWarnings("ModifyCollectionInEnhancedForLoop")
public static List<TransportProtocol> getTransportProtocols() {
int cnt = protocols.size();
List<TransportProtocol> res = new ArrayList<>(cnt);
for (WeakReference<TransportProtocol> ref : protocols) {
TransportProtocol proto = ref.get();
- if (proto != null)
+ if (proto != null) {
res.add(proto);
- else
+ } else {
protocols.remove(ref);
+ }
}
return Collections.unmodifiableList(res);
}
@@ -508,6 +512,7 @@ public abstract class Transport implements AutoCloseable {
* @throws org.eclipse.jgit.errors.TransportException
* the transport cannot open this URI.
*/
+ @SuppressWarnings("ModifyCollectionInEnhancedForLoop")
public static Transport open(Repository local, URIish uri, String remoteName)
throws NotSupportedException, TransportException {
for (WeakReference<TransportProtocol> ref : protocols) {
@@ -541,6 +546,7 @@ public abstract class Transport implements AutoCloseable {
* @throws org.eclipse.jgit.errors.TransportException
* if transport failed
*/
+ @SuppressWarnings("ModifyCollectionInEnhancedForLoop")
public static Transport open(URIish uri) throws NotSupportedException, TransportException {
for (WeakReference<TransportProtocol> ref : protocols) {
TransportProtocol proto = ref.get();
@@ -549,8 +555,9 @@ public abstract class Transport implements AutoCloseable {
continue;
}
- if (proto.canHandle(uri, null, null))
+ if (proto.canHandle(uri, null, null)) {
return proto.open(uri);
+ }
}
throw new NotSupportedException(MessageFormat.format(JGitText.get().URINotSupported, uri));