diff options
author | 2020-02-25 16:10:08 +0000 | |
---|---|---|
committer | 2020-02-26 08:33:06 +0000 | |
commit | 35840d835f581c2d61de1c57fe9963e36eb15c9f (patch) | |
tree | 10b8a6004cad1b4d1d63ebebe2aa26ae2af7f3e4 /context/context-management/src/main/java/org/onap | |
parent | aacc7442f046d44359934ea3d93f425a809e7616 (diff) |
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 <liam.fallon@est.tech>
Diffstat (limited to 'context/context-management/src/main/java/org/onap')
6 files changed, 79 insertions, 79 deletions
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFactory.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFactory.java index 2a9b8184b..3e7e0e8cb 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFactory.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFactory.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-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. @@ -48,29 +48,27 @@ public class DistributorFactory { * @throws ContextException on context distributor creation errors */ public Distributor getDistributor(final AxArtifactKey key) throws ContextException { - LOGGER.entry("Distributor factory, key=" + key); + LOGGER.debug("Distributor factory, key={}", key); Assertions.argumentOfClassNotNull(key, ContextException.class, "Parameter \"key\" may not be null"); // Get the class for the distributor using reflection - final DistributorParameters distributorParameters = ParameterService - .get(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + final DistributorParameters distributorParameters = + ParameterService.get(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); final String pluginClass = distributorParameters.getPluginClass(); Object contextDistributorObject = null; try { - contextDistributorObject = Class.forName(pluginClass).newInstance(); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { - LOGGER.error("Apex context distributor class not found for context distributor plugin \"" + pluginClass - + "\"", e); - throw new ContextException("Apex context distributor class not found for context distributor plugin \"" - + pluginClass + "\"", e); + contextDistributorObject = Class.forName(pluginClass).getDeclaredConstructor().newInstance(); + } catch (Exception e) { + throw new ContextException( + "Apex context distributor class not found for context distributor plugin \"" + pluginClass + "\"", + e); } // Check the class is a distributor if (!(contextDistributorObject instanceof Distributor)) { final String returnString = "Specified Apex context distributor plugin class \"" + pluginClass - + "\" does not implement the ContextDistributor interface"; - LOGGER.error(returnString); + + "\" does not implement the ContextDistributor interface"; throw new ContextException(returnString); } @@ -80,8 +78,8 @@ public class DistributorFactory { // Lock and load the context distributor contextDistributor.init(key); - LOGGER.exit("Distributor factory, key=" + key + ", selected distributor of class " - + contextDistributor.getClass()); + LOGGER.debug("Distributor factory, key={}, selected distributor of class {}", key, + contextDistributor.getClass()); return contextDistributor; } } diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/locking/LockManagerFactory.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/locking/LockManagerFactory.java index 3e9120672..923c83979 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/locking/LockManagerFactory.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/locking/LockManagerFactory.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. @@ -49,27 +50,29 @@ public class LockManagerFactory { public LockManager createLockManager(final AxArtifactKey key) throws ContextException { LOGGER.entry("Lock Manager factory, key=" + key); - final LockManagerParameters lockManagerParameters = ParameterService - .get(ContextParameterConstants.LOCKING_GROUP_NAME); + final LockManagerParameters lockManagerParameters = + ParameterService.get(ContextParameterConstants.LOCKING_GROUP_NAME); // Get the class for the lock manager using reflection Object lockManagerObject = null; final String pluginClass = lockManagerParameters.getPluginClass(); try { - lockManagerObject = Class.forName(pluginClass).newInstance(); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { - LOGGER.error("Apex context lock manager class not found for context lock manager plugin \"" + pluginClass - + "\"", e); - throw new ContextException("Apex context lock manager class not found for context lock manager plugin \"" - + pluginClass + "\"", e); + lockManagerObject = Class.forName(pluginClass).getDeclaredConstructor().newInstance(); + } catch (Exception e) { + LOGGER.error( + "Apex context lock manager class not found for context lock manager plugin \"" + pluginClass + "\"", + e); + throw new ContextException( + "Apex context lock manager class not found for context lock manager plugin \"" + pluginClass + "\"", + e); } // Check the class is a lock manager if (!(lockManagerObject instanceof LockManager)) { LOGGER.error("Specified Apex context lock manager plugin class \"{}\" " - + "does not implement the LockManager interface", pluginClass); + + "does not implement the LockManager interface", pluginClass); throw new ContextException("Specified Apex context lock manager plugin class \"" + pluginClass - + "\" does not implement the LockManager interface"); + + "\" does not implement the LockManager interface"); } // The context lock manager to return diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/persistence/PersistorFactory.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/persistence/PersistorFactory.java index 74c067c44..fe06d2fdb 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/persistence/PersistorFactory.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/persistence/PersistorFactory.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-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. @@ -51,27 +51,27 @@ public class PersistorFactory { LOGGER.entry("persistor factory, key=" + key); Assertions.argumentOfClassNotNull(key, ContextException.class, "Parameter \"key\" may not be null"); - final PersistorParameters persistorParameters = ParameterService - .get(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + final PersistorParameters persistorParameters = + ParameterService.get(ContextParameterConstants.PERSISTENCE_GROUP_NAME); // Get the class for the persistor using reflection Object persistorObject = null; final String pluginClass = persistorParameters.getPluginClass(); try { - persistorObject = Class.forName(pluginClass).newInstance(); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + persistorObject = Class.forName(pluginClass).getDeclaredConstructor().newInstance(); + } catch (Exception e) { LOGGER.error("Apex context persistor class not found for context persistor plugin \"" + pluginClass + "\"", - e); - throw new ContextException("Apex context persistor class not found for context persistor plugin \"" - + pluginClass + "\"", e); + e); + throw new ContextException( + "Apex context persistor class not found for context persistor plugin \"" + pluginClass + "\"", e); } // Check the class is a persistor if (!(persistorObject instanceof Persistor)) { LOGGER.error("Specified Apex context persistor plugin class \"{}\" " - + "does not implement the ContextDistributor interface", pluginClass); + + "does not implement the ContextDistributor interface", pluginClass); throw new ContextException("Specified Apex context persistor plugin class \"" + pluginClass - + "\" does not implement the ContextDistributor interface"); + + "\" does not implement the ContextDistributor interface"); } // The persistor to return diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java index ca1fa78f4..260482c61 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-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. @@ -67,9 +67,9 @@ public abstract class AbstractSchemaHelper implements SchemaHelper { @Override public void init(final AxKey incomingUserKey, final AxContextSchema incomingSchema) { Assertions.argumentOfClassNotNull(incomingUserKey, ContextRuntimeException.class, - "incomingUserKey may not be null"); + "incomingUserKey may not be null"); Assertions.argumentOfClassNotNull(incomingSchema, ContextRuntimeException.class, - "incomingSchema may not be null"); + "incomingSchema may not be null"); this.userKey = incomingUserKey; this.schema = incomingSchema; @@ -113,18 +113,18 @@ public abstract class AbstractSchemaHelper implements SchemaHelper { @Override public Object createNewInstance() { if (schemaClass == null) { - final String returnString = userKey.getId() - + ": could not create an instance, schema class for the schema is null"; + final String returnString = + userKey.getId() + ": could not create an instance, schema class for the schema is null"; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } try { - return schemaClass.newInstance(); + return schemaClass.getDeclaredConstructor().newInstance(); } catch (final Exception e) { - final String returnString = userKey.getId() + ": could not create an instance of class \"" - + schemaClass.getName() + "\" using the default constructor \"" - + schemaClass.getSimpleName() + "()\""; + final String returnString = + userKey.getId() + ": could not create an instance of class \"" + schemaClass.getName() + + "\" using the default constructor \"" + schemaClass.getSimpleName() + "()\""; LOGGER.warn(returnString, e); throw new ContextRuntimeException(returnString, e); } @@ -136,8 +136,8 @@ public abstract class AbstractSchemaHelper implements SchemaHelper { @Override public Object createNewInstance(final String stringValue) { if (schemaClass == null) { - final String returnString = userKey.getId() - + ": could not create an instance, schema class for the schema is null"; + final String returnString = + userKey.getId() + ": could not create an instance, schema class for the schema is null"; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } @@ -149,9 +149,9 @@ public abstract class AbstractSchemaHelper implements SchemaHelper { // Invoke the constructor return stringConstructor.newInstance(stringValue); } catch (final Exception e) { - final String returnString = userKey.getId() + ": could not create an instance of class \"" - + schemaClass.getName() + "\" using the string constructor \"" - + schemaClass.getSimpleName() + "(String)\""; + final String returnString = + userKey.getId() + ": could not create an instance of class \"" + schemaClass.getName() + + "\" using the string constructor \"" + schemaClass.getSimpleName() + "(String)\""; LOGGER.warn(returnString, e); throw new ContextRuntimeException(returnString); } diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java index 4f0c233db..d1cd3b11b 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-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,15 +56,15 @@ public class SchemaHelperFactory { public SchemaHelper createSchemaHelper(final AxKey owningEntityKey, final AxArtifactKey schemaKey) { LOGGER.entry("schema helper factory, owningEntityKey=" + owningEntityKey); Assertions.argumentOfClassNotNull(owningEntityKey, ContextRuntimeException.class, - "Parameter \"owningEntityKey\" may not be null"); + "Parameter \"owningEntityKey\" may not be null"); Assertions.argumentOfClassNotNull(schemaKey, ContextRuntimeException.class, - "Parameter \"schemaKey\" may not be null"); + "Parameter \"schemaKey\" may not be null"); // Get the schema for items in the album final AxContextSchema schema = ModelService.getModel(AxContextSchemas.class).get(schemaKey); if (schema == null) { - final String resultString = "schema \"" + schemaKey.getId() + "\" for entity " + owningEntityKey.getId() - + " does not exist"; + final String resultString = + "schema \"" + schemaKey.getId() + "\" for entity " + owningEntityKey.getId() + " does not exist"; LOGGER.warn(resultString); throw new ContextRuntimeException(resultString); } @@ -73,11 +73,11 @@ public class SchemaHelperFactory { final SchemaParameters schemaParameters = ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME); // Get the class for the schema helper from the schema parameters - final SchemaHelperParameters schemaHelperParameters = schemaParameters - .getSchemaHelperParameters(schema.getSchemaFlavour()); + final SchemaHelperParameters schemaHelperParameters = + schemaParameters.getSchemaHelperParameters(schema.getSchemaFlavour()); if (schemaHelperParameters == null) { final String resultString = "context schema helper parameters not found for context schema \"" - + schema.getSchemaFlavour() + "\""; + + schema.getSchemaFlavour() + "\""; LOGGER.warn(resultString); throw new ContextRuntimeException(resultString); } @@ -86,10 +86,10 @@ public class SchemaHelperFactory { Object schemaHelperObject = null; final String pluginClass = schemaHelperParameters.getSchemaHelperPluginClass(); try { - schemaHelperObject = Class.forName(pluginClass).newInstance(); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + schemaHelperObject = Class.forName(pluginClass).getDeclaredConstructor().newInstance(); + } catch (final Exception e) { final String resultString = "Apex context schema helper class not found for context schema helper plugin \"" - + pluginClass + "\""; + + pluginClass + "\""; LOGGER.warn(resultString, e); throw new ContextRuntimeException(resultString, e); } @@ -97,7 +97,7 @@ public class SchemaHelperFactory { // Check the class is a schema helper if (!(schemaHelperObject instanceof SchemaHelper)) { final String resultString = "Specified Apex context schema helper plugin class \"" + pluginClass - + "\" does not implement the SchemaHelper interface"; + + "\" does not implement the SchemaHelper interface"; LOGGER.warn(resultString); throw new ContextRuntimeException(resultString); } @@ -109,7 +109,7 @@ public class SchemaHelperFactory { schemaHelper.init(owningEntityKey.getKey(), schema); LOGGER.exit("Schema Helper factory, owningEntityKey=" + owningEntityKey + ", selected schema helper of class " - + schemaHelper.getClass()); + + schemaHelper.getClass()); return schemaHelper; } } diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java index b36e00899..e4cdd0fdc 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-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. @@ -83,7 +83,7 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { } catch (final IllegalArgumentException e) { String resultSting = userKey.getId() + ": class/type " + schema.getSchema() + " for context schema \"" - + schema.getId() + "\" not found."; + + schema.getId() + "\" not found."; if (JavaSchemaHelper.BUILT_IN_MAP.get(javatype) != null) { resultSting += " Primitive types are not supported. Use the appropriate Java boxing type instead."; } else { @@ -104,8 +104,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { } if (getSchemaClass() == null) { - final String returnString = getUserKey().getId() - + ": could not create an instance, schema class for the schema is null"; + final String returnString = + getUserKey().getId() + ": could not create an instance, schema class for the schema is null"; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } @@ -120,9 +120,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { } final String returnString = getUserKey().getId() + ": the object \"" + incomingObject + "\" of type \"" - + incomingObject.getClass().getName() - + "\" is not an instance of JsonObject and is not assignable to \"" + getSchemaClass().getName() - + "\""; + + incomingObject.getClass().getName() + + "\" is not an instance of JsonObject and is not assignable to \"" + getSchemaClass().getName() + "\""; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } @@ -168,8 +167,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { return getGson().toJson(schemaObject); } else { final String returnString = getUserKey().getId() + ": object \"" + schemaObject.toString() - + "\" of class \"" + schemaObject.getClass().getName() + "\" not compatible with class \"" - + getSchemaClass().getName() + "\""; + + "\" of class \"" + schemaObject.getClass().getName() + "\" not compatible with class \"" + + getSchemaClass().getName() + "\""; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } @@ -225,8 +224,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { return stringConstructor.newInstance(object.toString()); } catch (final Exception e) { final String returnString = getUserKey().getId() + ": object \"" + object.toString() + "\" of class \"" - + object.getClass().getName() + "\" not compatible with class \"" - + getSchemaClass().getName() + "\""; + + object.getClass().getName() + "\" not compatible with class \"" + getSchemaClass().getName() + + "\""; LOGGER.warn(returnString, e); throw new ContextRuntimeException(returnString); } @@ -243,23 +242,23 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { // Get the Java schema helper parameters from the parameter service SchemaParameters schemaParameters = ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME); - JavaSchemaHelperParameters javaSchemaHelperParmeters = (JavaSchemaHelperParameters) schemaParameters - .getSchemaHelperParameterMap().get("Java"); + JavaSchemaHelperParameters javaSchemaHelperParmeters = + (JavaSchemaHelperParameters) schemaParameters.getSchemaHelperParameterMap().get("Java"); if (javaSchemaHelperParmeters == null) { javaSchemaHelperParmeters = new JavaSchemaHelperParameters(); } for (JavaSchemaHelperJsonAdapterParameters jsonAdapterEntry : javaSchemaHelperParmeters.getJsonAdapters() - .values()) { + .values()) { Object adapterObject; try { - adapterObject = jsonAdapterEntry.getAdaptorClazz().newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + adapterObject = jsonAdapterEntry.getAdaptorClazz().getDeclaredConstructor().newInstance(); + } catch (Exception e) { final String returnString = getUserKey().getId() + ": instantiation of adapter class \"" - + jsonAdapterEntry.getAdaptorClass() + "\" to decode and encode class \"" - + jsonAdapterEntry.getAdaptedClass() + "\" failed: " + e.getMessage(); + + jsonAdapterEntry.getAdaptorClass() + "\" to decode and encode class \"" + + jsonAdapterEntry.getAdaptedClass() + "\" failed: " + e.getMessage(); LOGGER.warn(returnString, e); throw new ContextRuntimeException(returnString); } |