diff --git a/testing/src/main/java/io/grpc/testing/GrpcCleanupRule.java b/testing/src/main/java/io/grpc/testing/GrpcCleanupRule.java index fb111525704..f518dcb9e52 100644 --- a/testing/src/main/java/io/grpc/testing/GrpcCleanupRule.java +++ b/testing/src/main/java/io/grpc/testing/GrpcCleanupRule.java @@ -22,6 +22,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Stopwatch; import com.google.common.base.Ticker; +import com.google.common.collect.Lists; import io.grpc.ExperimentalApi; import io.grpc.ManagedChannel; import io.grpc.Server; @@ -170,8 +171,8 @@ protected void after() { InterruptedException interrupted = null; if (!abruptShutdown) { - for (int i = resources.size() - 1; i >= 0; i--) { - resources.get(i).cleanUp(); + for (Resource resource : Lists.reverse(resources)) { + resource.cleanUp(); } for (int i = resources.size() - 1; i >= 0; i--) { @@ -190,8 +191,8 @@ protected void after() { } if (!resources.isEmpty()) { - for (int i = resources.size() - 1; i >= 0; i--) { - resources.get(i).forceCleanUp(); + for (Resource resource : Lists.reverse(resources)) { + resource.forceCleanUp(); } try {