This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 6ce1a1b  PMD cleanup
6ce1a1b is described below

commit 6ce1a1b4114f138b0f5ce7a377af46c816be6c69
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Fri Jul 12 17:07:11 2019 +0100

    PMD cleanup
---
 .../cxf/tools/wsdlto/WSDLToJavaContainer.java      | 34 ++++++++-----------
 .../apache/cxf/tools/wsdlto/core/PluginLoader.java | 39 ++++++++++------------
 2 files changed, 30 insertions(+), 43 deletions(-)

diff --git 
a/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
 
b/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
index 3a30cd6..31cf7f6 100644
--- 
a/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
+++ 
b/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
@@ -128,7 +128,6 @@ public class WSDLToJavaContainer extends 
AbstractCXFToolContainer {
         boolean isWsdlList = context.optionSet(ToolConstants.CFG_WSDLLIST);
 
         if (isWsdlList) {
-            BufferedReader reader = null;
             try {
                 ToolContext initialContextState = context.makeCopy();
                 String wsdlURL = 
(String)context.get(ToolConstants.CFG_WSDLURL);
@@ -136,29 +135,22 @@ public class WSDLToJavaContainer extends 
AbstractCXFToolContainer {
 
                 URL url = new URL(wsdlURL);
                 InputStream is = (InputStream)url.getContent();
-                reader = new BufferedReader(new InputStreamReader(is));
-                String tempLine = null;
-                while ((tempLine = reader.readLine()) != null) {
-                    ToolContext freshContext = initialContextState.makeCopy();
-                    freshContext.put(ToolConstants.CFG_WSDLURL, tempLine);
-                    setContext(freshContext);
-                    buildToolContext();
-
-                    processWsdl();
-                }
-                if (context.getErrorListener().getErrorCount() > 0) {
-                    context.getErrorListener().throwToolException();
+                try (BufferedReader reader = new BufferedReader(new 
InputStreamReader(is))) {
+                    String tempLine = null;
+                    while ((tempLine = reader.readLine()) != null) {
+                        ToolContext freshContext = 
initialContextState.makeCopy();
+                        freshContext.put(ToolConstants.CFG_WSDLURL, tempLine);
+                        setContext(freshContext);
+                        buildToolContext();
+
+                        processWsdl();
+                    }
+                    if (context.getErrorListener().getErrorCount() > 0) {
+                        context.getErrorListener().throwToolException();
+                    }
                 }
             } catch (IOException e) {
                 throw new ToolException(e);
-            } finally {
-                try {
-                    if (reader != null) {
-                        reader.close();
-                    }
-                } catch (IOException e) {
-                    throw new ToolException(e);
-                }
             }
         } else {
             processWsdl();
diff --git 
a/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/PluginLoader.java
 
b/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/PluginLoader.java
index 1ff3ead..3261ffb 100644
--- 
a/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/PluginLoader.java
+++ 
b/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/core/PluginLoader.java
@@ -131,14 +131,14 @@ public final class PluginLoader {
         try {
             LOG.log(Level.FINE, "PLUGIN_LOADING", resource);
             loadPlugin(getPlugin(resource));
-        } catch (JAXBException e) {
-            Message msg = new Message("PLUGIN_LOAD_FAIL", LOG, resource);
-            LOG.log(Level.SEVERE, msg.toString());
-            throw new ToolException(msg, e);
         } catch (FileNotFoundException fe) {
             Message msg = new Message("PLUGIN_FILE_NOT_FOUND", LOG, resource);
             LOG.log(Level.SEVERE, msg.toString());
             throw new ToolException(msg, fe);
+        } catch (JAXBException | IOException e) {
+            Message msg = new Message("PLUGIN_LOAD_FAIL", LOG, resource);
+            LOG.log(Level.SEVERE, msg.toString());
+            throw new ToolException(msg, e);
         }
 
     }
@@ -202,22 +202,23 @@ public final class PluginLoader {
         return plugin;
     }
 
-    protected Plugin getPlugin(String resource) throws JAXBException, 
FileNotFoundException {
+    protected Plugin getPlugin(String resource) throws JAXBException, 
IOException, FileNotFoundException {
         Plugin plugin = plugins.get(resource);
         if (plugin == null) {
-            InputStream is = null;
-            if (new File(resource).exists()) {
-                is = new BufferedInputStream(new FileInputStream(new 
File(resource)));
-            } else {
-                is = getClass().getResourceAsStream(resource);
-            }
+            File resourceFile = new File(resource);
 
-            if (is == null) {
-                Message msg = new Message("PLUGIN_MISSING", LOG, resource);
-                LOG.log(Level.SEVERE, msg.toString());
-                throw new ToolException(msg);
+            try (InputStream is = resourceFile.exists()
+                ? new BufferedInputStream(new FileInputStream(resourceFile))
+                : getClass().getResourceAsStream(resource)) {
+
+                if (is == null) {
+                    Message msg = new Message("PLUGIN_MISSING", LOG, resource);
+                    LOG.log(Level.SEVERE, msg.toString());
+                    throw new ToolException(msg);
+                }
+                plugin = getPlugin(is);
             }
-            plugin = getPlugin(is);
+
             if (plugin == null || StringUtils.isEmpty(plugin.getName())) {
                 Message msg = new Message("PLUGIN_LOAD_FAIL", LOG, resource);
                 LOG.log(Level.SEVERE, msg.toString());
@@ -234,12 +235,6 @@ public final class PluginLoader {
             return JAXBUtils.unmarshall(jaxbContext, doc.getDocumentElement(), 
Plugin.class).getValue();
         } catch (XMLStreamException xse) {
             throw new JAXBException(xse);
-        } finally {
-            try {
-                is.close();
-            } catch (IOException e) {
-                //ignore
-            }
         }
     }
 

Reply via email to