From: Robert Varga Date: Tue, 9 Oct 2018 15:10:33 +0000 (+0200) Subject: Remove use of Class.newInstance() X-Git-Tag: release/neon~79 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=c3b47511c453ecc7692c7e5b3602c606996b4aba;hp=ee1e0761d70281191400a8f85cc2e0c5156d2c3f Remove use of Class.newInstance() This method is deprecated in JDK9+, migrate to its replacement. This also means that any exceptions thrown are wrapped in InvocationTargetException, hence we can (and are forced by FindBugs) replace catching of Exception with catching of ClassCastException and ReflectiveOperationException. Change-Id: Iefd48ecef653fc73f74b2a77ac1ab7891b2575d3 Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/DefaultConfigParamsImpl.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/DefaultConfigParamsImpl.java index 64502858a7..932069edda 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/DefaultConfigParamsImpl.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/DefaultConfigParamsImpl.java @@ -216,8 +216,8 @@ public class DefaultConfigParamsImpl implements ConfigParams { try { String className = DefaultConfigParamsImpl.this.customRaftPolicyImplementationClass; LOG.info("Trying to use custom RaftPolicy {}", className); - return (RaftPolicy)Class.forName(className).newInstance(); - } catch (Exception e) { + return (RaftPolicy)Class.forName(className).getDeclaredConstructor().newInstance(); + } catch (ClassCastException | ReflectiveOperationException e) { if (LOG.isDebugEnabled()) { LOG.error("Could not create custom raft policy, will stick with default", e); } else {