From 35840d835f581c2d61de1c57fe9963e36eb15c9f Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 25 Feb 2020 16:10:08 +0000 Subject: Fix Java 11/Checkstyle/Sonar warnings A number of Java 11, checkstyle, and SONAR warnings have crept into the Apex codebase over the last number of reviews. This change fixes those issues. Issue-ID: POLICY-1913 Change-Id: I2afd607e80f48323355380fb2fe5e048e18879f9 Signed-off-by: liamfallon --- .../apex/plugins/executor/java/JavaStateFinalizerExecutor.java | 5 +++-- .../onap/policy/apex/plugins/executor/java/JavaTaskExecutor.java | 8 +++++--- .../policy/apex/plugins/executor/java/JavaTaskSelectExecutor.java | 6 ++++-- 3 files changed, 12 insertions(+), 7 deletions(-) (limited to 'plugins/plugins-executor') diff --git a/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutor.java b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutor.java index ce242bafb..7eaaa0415 100644 --- a/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutor.java +++ b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutor.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,7 +57,7 @@ public class JavaStateFinalizerExecutor extends StateFinalizerExecutor { // Get the class for state finalizer execution try { // Create the state finalizer logic object from the byte code of the class - stateFinalizerLogicObject = Class.forName(getSubject().getLogic()).newInstance(); + stateFinalizerLogicObject = Class.forName(getSubject().getLogic()).getDeclaredConstructor().newInstance(); } catch (final Exception e) { LOGGER.error("instantiation error on Java class \"" + getSubject().getLogic() + "\"", e); throw new StateMachineException("instantiation error on Java class \"" + getSubject().getLogic() + "\"", e); @@ -87,7 +88,7 @@ public class JavaStateFinalizerExecutor extends StateFinalizerExecutor { // to invoke the // task logic in the Java class final Method method = stateFinalizerLogicObject.getClass().getDeclaredMethod("getStateOutput", - new Class[] { StateFinalizerExecutionContext.class }); + new Class[] {StateFinalizerExecutionContext.class}); returnValue = (boolean) method.invoke(stateFinalizerLogicObject, getExecutionContext()); } catch (final Exception e) { LOGGER.error("execute: state finalizer logic failed to run for state finalizer \"" + getSubject().getId() diff --git a/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutor.java b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutor.java index 1ceeba3b1..61ab6778e 100644 --- a/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutor.java +++ b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutor.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,7 +57,8 @@ public class JavaTaskExecutor extends TaskExecutor { // Get the class for task execution try { // Create the task logic object from the byte code of the class - taskLogicObject = Class.forName(getSubject().getTaskLogic().getLogic()).newInstance(); + taskLogicObject = + Class.forName(getSubject().getTaskLogic().getLogic()).getDeclaredConstructor().newInstance(); } catch (final Exception e) { LOGGER.error("instantiation error on Java class \"" + getSubject().getTaskLogic().getLogic() + "\"", e); throw new StateMachineException( @@ -86,8 +88,8 @@ public class JavaTaskExecutor extends TaskExecutor { // Find and call the method with the signature "public boolean getEvent(final TaskExecutionContext executor) // throws ApexException" to invoke the // task logic in the Java class - final Method method = taskLogicObject.getClass().getDeclaredMethod("getEvent", - new Class[] { TaskExecutionContext.class }); + final Method method = + taskLogicObject.getClass().getDeclaredMethod("getEvent", new Class[] {TaskExecutionContext.class}); returnValue = (boolean) method.invoke(taskLogicObject, getExecutionContext()); } catch (final Exception e) { LOGGER.error("execute: task logic failed to run for task \"" + getSubject().getKey().getId() + "\""); diff --git a/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutor.java b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutor.java index 17758b19e..244a80a3c 100644 --- a/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutor.java +++ b/plugins/plugins-executor/plugins-executor-java/src/main/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutor.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,7 +58,8 @@ public class JavaTaskSelectExecutor extends TaskSelectExecutor { // Get the class for task selection try { // Create the task logic object from the byte code of the class - taskSelectionLogicObject = Class.forName(getSubject().getTaskSelectionLogic().getLogic()).newInstance(); + taskSelectionLogicObject = Class.forName(getSubject().getTaskSelectionLogic().getLogic()) + .getDeclaredConstructor().newInstance(); } catch (final Exception e) { LOGGER.error( "instantiation error on Java class \"" + getSubject().getTaskSelectionLogic().getLogic() + "\"", e); @@ -89,7 +91,7 @@ public class JavaTaskSelectExecutor extends TaskSelectExecutor { // executor)" to invoke the task selection // logic in the Java class final Method method = taskSelectionLogicObject.getClass().getDeclaredMethod("getTask", - new Class[] { TaskSelectionExecutionContext.class }); + new Class[] {TaskSelectionExecutionContext.class}); returnValue = (boolean) method.invoke(taskSelectionLogicObject, getExecutionContext()); } catch (final Exception e) { LOGGER.error( -- cgit 1.2.3-korg