Fix suspicious proxy object usage (reported by new inspection IDEA-242644)
authorNikita Skvortsov <nikita.skvortsov@jetbrains.com>
Mon, 8 Jun 2020 06:58:55 +0000 (09:58 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Mon, 8 Jun 2020 07:15:54 +0000 (07:15 +0000)
GitOrigin-RevId: 447d11436034d5208a7d2878def4a438d5c70331

aether-dependency-resolver/src/org/jetbrains/idea/maven/aether/ArtifactRepositoryManager.java

index 9d004fce8dbe28690e884b2b8672878ece5bffdf..fcb2326c604cb3d45292ee4dca7679834f37bb32 100644 (file)
@@ -39,9 +39,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.File;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
 import java.util.*;
 
 /**
@@ -97,25 +94,42 @@ public class ArtifactRepositoryManager {
     myRemoteRepositories.addAll(remoteRepositories);
     final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
     if (progressConsumer != ProgressConsumer.DEAF) {
-      session.setTransferListener((TransferListener)Proxy
-        .newProxyInstance(session.getClass().getClassLoader(), new Class[]{TransferListener.class}, new InvocationHandler() {
-          private final EnumSet<TransferEvent.EventType> checkCancelEvents = EnumSet.of(TransferEvent.EventType.INITIATED, TransferEvent.EventType.STARTED, TransferEvent.EventType.PROGRESSED);
+      session.setTransferListener(new TransferListener() {
         @Override
-        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-          final Object event = args[0];
-          if (event instanceof TransferEvent) {
-            final TransferEvent.EventType type = ((TransferEvent)event).getType();
-            if (checkCancelEvents.contains(type) && progressConsumer.isCanceled()) {
-              throw new TransferCancelledException();
-            }
-            progressConsumer.consume(event.toString());
-            //if (type != TransferEvent.EventType.PROGRESSED) {
-            //  progressConsumer.consume(event.toString());
-            //}
+        public void transferInitiated(TransferEvent event) throws TransferCancelledException {
+          handle(event);
+        }
+
+        @Override
+        public void transferStarted(TransferEvent event) throws TransferCancelledException {
+          handle(event);
+        }
+
+        @Override
+        public void transferProgressed(TransferEvent event) throws TransferCancelledException {
+          handle(event);
+        }
+
+        @Override
+        public void transferCorrupted(TransferEvent event) throws TransferCancelledException {
+        }
+
+        @Override
+        public void transferSucceeded(TransferEvent event) {
+
+        }
+
+        @Override
+        public void transferFailed(TransferEvent event) {
+        }
+
+        private void handle(TransferEvent event) throws TransferCancelledException {
+          if (progressConsumer.isCanceled()) {
+            throw new TransferCancelledException();
           }
-          return null;
+          progressConsumer.consume(event.toString());
         }
-      }));
+      });
     }
     // setup session here