diff options
author | liamfallon <liam.fallon@est.tech> | 2020-02-25 16:10:08 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2020-02-26 08:33:06 +0000 |
commit | 35840d835f581c2d61de1c57fe9963e36eb15c9f (patch) | |
tree | 10b8a6004cad1b4d1d63ebebe2aa26ae2af7f3e4 /core/core-infrastructure | |
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 'core/core-infrastructure')
-rw-r--r-- | core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.java | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.java index 464a601e1..7695e29fd 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.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. @@ -69,8 +70,8 @@ public class SingleClassBuilder { */ public void compile() throws JavaHandlingException { // Get the list of compilation units, there is only one here - final List<? extends JavaFileObject> compilationUnits = Arrays - .asList(new SingleClassCompilationUnit(className, sourceCode)); + final List<? extends JavaFileObject> compilationUnits = + Arrays.asList(new SingleClassCompilationUnit(className, sourceCode)); // Allows us to get diagnostics from the compilation final DiagnosticCollector<JavaFileObject> diagnosticListener = new DiagnosticCollector<>(); @@ -80,11 +81,11 @@ public class SingleClassBuilder { // Set up the target file manager and call the compiler singleFileManager = new SingleFileManager(compiler, new SingleClassByteCodeFileObject(className)); - final JavaCompiler.CompilationTask task = compiler.getTask(null, singleFileManager, diagnosticListener, null, - null, compilationUnits); + final JavaCompiler.CompilationTask task = + compiler.getTask(null, singleFileManager, diagnosticListener, null, null, compilationUnits); // Check if the compilation worked - if (!task.call()) { + if (Boolean.FALSE.equals(task.call())) { final StringBuilder builder = new StringBuilder(); for (final Diagnostic<? extends JavaFileObject> diagnostic : diagnosticListener.getDiagnostics()) { builder.append("code:"); @@ -114,20 +115,21 @@ public class SingleClassBuilder { * Create a new instance of the Java class using its byte code definition. * * @return A new instance of the object - * @throws InstantiationException if an instance of the object cannot be created, for example if the class has no - * default constructor - * @throws IllegalAccessException the caller does not have permission to call the class - * @throws ClassNotFoundException the byte code for the class is not found in the class loader - * @throws JavaHandlingException the java handling exception if the Java class source code is not compiled + * @throws JavaHandlingException on errors creating the object */ - public Object createObject() throws InstantiationException, IllegalAccessException, ClassNotFoundException, - JavaHandlingException { + public Object createObject() + throws InstantiationException, IllegalAccessException, ClassNotFoundException, JavaHandlingException { if (singleFileManager == null) { String message = "error instantiating instance for class \"" + className + "\": code may not be compiled"; LOGGER.warn(message); throw new JavaHandlingException(message); } - return singleFileManager.getClassLoader(null).findClass(className).newInstance(); + try { + return singleFileManager.getClassLoader(null).findClass(className).getDeclaredConstructor().newInstance(); + } catch (Exception e) { + return new JavaHandlingException("could not create java class", e); + } + } } |