[tor-commits] [metrics-lib/master] Remove deprecation warning.

karsten at torproject.org karsten at torproject.org
Wed Nov 20 11:50:26 UTC 2019


commit 25ea064dc8214385f2077706b2635f2da0d530fa
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Wed Nov 20 10:34:35 2019 +0100

    Remove deprecation warning.
    
    Class#newInstance is deprecated in Java 9 and higher, which doesn't
    affect us yet in Java 8. But the suggested replacement already works
    in Java 8, so that we can safely switch to that.
---
 src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java b/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java
index e755e42..55fbcf3 100644
--- a/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java
+++ b/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java
@@ -146,10 +146,9 @@ public final class DescriptorSourceFactory {
               + ".");
       }
       object = ClassLoader.getSystemClassLoader().loadClass(clazzName)
-          .newInstance();
+          .getDeclaredConstructor().newInstance();
       log.info("Serving implementation {} for {}.", clazzName, type);
-    } catch (ClassNotFoundException | InstantiationException
-             | IllegalAccessException ex) {
+    } catch (ReflectiveOperationException ex) {
       throw new RuntimeException("Cannot load class "
           + clazzName + "for type " + type, ex);
     }





More information about the tor-commits mailing list