[tor-commits] [onionoo/release] Remove deprecation warning.

karsten at torproject.org karsten at torproject.org
Thu Nov 28 09:20:38 UTC 2019


commit afe4045b50330bf0c65eeae393eeefebfa191817
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Wed Nov 20 11:16:03 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.
---
 .../java/org/torproject/metrics/onionoo/docs/DocumentStore.java   | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/torproject/metrics/onionoo/docs/DocumentStore.java b/src/main/java/org/torproject/metrics/onionoo/docs/DocumentStore.java
index 778bab9..2963db2 100644
--- a/src/main/java/org/torproject/metrics/onionoo/docs/DocumentStore.java
+++ b/src/main/java/org/torproject/metrics/onionoo/docs/DocumentStore.java
@@ -524,9 +524,9 @@ public class DocumentStore {
       Class<T> documentType, String documentString) {
     T result = null;
     try {
-      result = documentType.newInstance();
+      result = documentType.getDeclaredConstructor().newInstance();
       result.setFromDocumentString(documentString);
-    } catch (InstantiationException | IllegalAccessException e) {
+    } catch (ReflectiveOperationException e) {
       /* Handle below. */
       log.error(e.getMessage(), e);
     }
@@ -558,9 +558,9 @@ public class DocumentStore {
       Class<T> documentType, String documentString) {
     T result = null;
     try {
-      result = documentType.newInstance();
+      result = documentType.getDeclaredConstructor().newInstance();
       result.setDocumentString(documentString);
-    } catch (InstantiationException | IllegalAccessException e) {
+    } catch (ReflectiveOperationException e) {
       /* Handle below. */
       log.error(e.getMessage(), e);
     }





More information about the tor-commits mailing list