Repository: incubator-tamaya Updated Branches: refs/heads/master 3dc29e25b -> 14d3e2ba0
TAMAYA-53 Fixed more issues reported by FindBugs. Some seems to be false positives. Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/14d3e2ba Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/14d3e2ba Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/14d3e2ba Branch: refs/heads/master Commit: 14d3e2ba0a10fc505294d5739a71a4a879725d35 Parents: 3dc29e2 Author: Oliver B. Fischer <[email protected]> Authored: Sat Jan 17 12:39:32 2015 +0100 Committer: Oliver B. Fischer <[email protected]> Committed: Sat Jan 17 12:39:32 2015 +0100 ---------------------------------------------------------------------- .../resources/findbugs/findbugs-exclude.xml | 32 ++++++++++++++++---- .../format/CommonsConfigPropertySource.java | 8 ++--- .../apache/tamaya/format/PropertiesFormat.java | 14 ++------- .../tamaya/format/PropertiesXmlFormat.java | 20 ++---------- .../resource/internal/ClasspathCollector.java | 4 +-- .../internal/DefaultResourceResolver.java | 9 +++--- 6 files changed, 42 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/14d3e2ba/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml ---------------------------------------------------------------------- diff --git a/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml b/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml index 539f9fb..9948661 100644 --- a/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml +++ b/buildconfigurations/src/main/resources/findbugs/findbugs-exclude.xml @@ -48,14 +48,34 @@ under the License. <Match> <!-- Note: - Please check this exclusion. Maybe this is not a false - positive. - Oliver B. Fischer, 17.01.2015 + False positive reported by FindBugs 3.0.0 for exception + thrown in try-with-resource. + Oliver B. Fischer, 17.01.2015 --> - <Class name="org.apache.tamaya.core.internal.PropertiesFileLoader" - params="java.lang.String" - returns="java.util.Set"/> + <Class name='org.apache.tamaya.format.PropertiesXmlFormat'/> + <Bug pattern="REC_CATCH_EXCEPTION"/> </Match> + <Match> + <!-- Note: + False positive reported by FindBugs 3.0.0 for exception + thrown in try-with-resource. + Oliver B. Fischer, 17.01.2015 + --> + <Class name='org.apache.tamaya.format.PropertiesFormat'/> + <Bug pattern="REC_CATCH_EXCEPTION"/> + </Match> + <Match> + <!-- Note: + Intended. See the inline comment on this issue in the source file + in revision ae66299e25b41167008021ffe95cad236f6e2bd3 + Oliver B. Fischer, 17.01.2015 + --> + <Class name='org.apache.tamaya.resource.internal.ClasspathCollector'/> + <Method name="doFindPathMatchingJarResources" + returns="java.util.Collection"/> + <Bug pattern="OS_OPEN_STREAM"/> + + </Match> </FindBugsFilter> http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/14d3e2ba/modules/formats/src/main/java/org/apache/tamaya/format/CommonsConfigPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/CommonsConfigPropertySource.java b/modules/formats/src/main/java/org/apache/tamaya/format/CommonsConfigPropertySource.java index 31b2b83..5c9078d 100644 --- a/modules/formats/src/main/java/org/apache/tamaya/format/CommonsConfigPropertySource.java +++ b/modules/formats/src/main/java/org/apache/tamaya/format/CommonsConfigPropertySource.java @@ -32,7 +32,7 @@ import java.util.Objects; public class CommonsConfigPropertySource implements PropertySource { private Configuration commonsConfig; - private Integer ordinal; + private int ordinal; private String name; public CommonsConfigPropertySource(int ordinal, String name, Configuration commonsConfig) { @@ -42,18 +42,18 @@ public class CommonsConfigPropertySource implements PropertySource { } public CommonsConfigPropertySource(String name, Configuration commonsConfig) { - this.commonsConfig = Objects.requireNonNull(commonsConfig); + commonsConfig = Objects.requireNonNull(commonsConfig); this.name = Objects.requireNonNull(name); try { this.ordinal = commonsConfig.getInt(PropertySource.TAMAYA_ORDINAL); } catch (Exception e) { - // ignore + this.ordinal = 0; } } @Override public int getOrdinal() { - return ordinal == null ? 0 : ordinal.intValue(); + return ordinal; } @Override http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/14d3e2ba/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java ---------------------------------------------------------------------- diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java index ab7b029..48a5288 100644 --- a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java +++ b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java @@ -40,12 +40,6 @@ public class PropertiesFormat implements ConfigurationFormat { */ private final static Logger LOG = Logger.getLogger(PropertiesFormat.class.getName()); - /** - * Creates a new format instance. - */ - public PropertiesFormat() { - } - @Override public Set<String> getEntryTypes() { Set<String> set = new HashSet<>(); @@ -56,12 +50,8 @@ public class PropertiesFormat implements ConfigurationFormat { @SuppressWarnings("unchecked") @Override public Map<String, Map<String, String>> readConfiguration(URL url) { - final String name; - if (Objects.requireNonNull(url).getQuery() == null) { - name = "Properties(" + Objects.requireNonNull(url).toString() + ')'; - } else { - name = Objects.requireNonNull(url).getQuery(); - } + Objects.requireNonNull(url); + Map<String, Map<String, String>> result = new HashMap<>(); try (InputStream is = url.openStream()) { if (is != null) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/14d3e2ba/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java ---------------------------------------------------------------------- diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java index 7aa549b..4ec0898 100644 --- a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java +++ b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java @@ -20,12 +20,7 @@ package org.apache.tamaya.format; import java.io.InputStream; import java.net.URL; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Objects; -import java.util.Properties; -import java.util.Set; +import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -41,11 +36,6 @@ public class PropertiesXmlFormat implements ConfigurationFormat { */ private final static Logger LOG = Logger.getLogger(PropertiesXmlFormat.class.getName()); - /** - * Creates a new format instance. - */ - public PropertiesXmlFormat() { } - @Override public Set<String> getEntryTypes() { Set<String> set = new HashSet<>(); @@ -57,12 +47,8 @@ public class PropertiesXmlFormat implements ConfigurationFormat { @SuppressWarnings("unchecked") @Override public Map<String, Map<String, String>> readConfiguration(URL url) { - final String name; - if (Objects.requireNonNull(url).getQuery() == null) { - name = "XML-Properties(" + Objects.requireNonNull(url).toString() + ')'; - } else { - name = Objects.requireNonNull(url).getQuery(); - } + Objects.requireNonNull(url); + Map<String, Map<String, String>> result = new HashMap<>(); try (InputStream is = url.openStream()) { if (is != null) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/14d3e2ba/modules/resources/src/main/java/org/apache/tamaya/resource/internal/ClasspathCollector.java ---------------------------------------------------------------------- diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/ClasspathCollector.java b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/ClasspathCollector.java index c47bd10..83307d3 100644 --- a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/ClasspathCollector.java +++ b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/ClasspathCollector.java @@ -130,11 +130,11 @@ public class ClasspathCollector { result.addAll(FileCollector.traverseAndSelectFromChildren(getFile(resource), locator.getSubPathTokens(), 0)); } - } catch (Exception e) { + } catch (URISyntaxException | IOException e) { LOG.log(Level.SEVERE, "Error locating resources for: " + expression, e); } } - } catch (IOException e) { + } catch (IOException | RuntimeException e) { LOG.log(Level.SEVERE, "Error locating resources for: " + expression, e); } return result; http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/14d3e2ba/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java ---------------------------------------------------------------------- diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java index c90e53a..df87436 100644 --- a/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java +++ b/modules/resources/src/main/java/org/apache/tamaya/resource/internal/DefaultResourceResolver.java @@ -22,6 +22,7 @@ import org.apache.tamaya.resource.ResourceResolver; import javax.annotation.Priority; import java.io.File; +import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; @@ -66,7 +67,7 @@ public class DefaultResourceResolver implements ResourceResolver { } resources.addAll(found); return !found.isEmpty(); - } catch (Exception e) { + } catch (RuntimeException e) { LOG.finest(() -> "Failed to load resource from CP: " + expression); } return false; @@ -87,7 +88,7 @@ public class DefaultResourceResolver implements ResourceResolver { resources.add(url); } return !resources.isEmpty(); - } catch (Exception e) { + } catch (IOException | RuntimeException e) { LOG.finest(() -> "Failed to load resource from CP: " + expression); } return false; @@ -106,7 +107,7 @@ public class DefaultResourceResolver implements ResourceResolver { resources.add(file.toURI().toURL()); return true; } - } catch (Exception e) { + } catch (IOException | RuntimeException e) { LOG.finest(() -> "Failed to load resource from file: " + expression); } return false; @@ -123,7 +124,7 @@ public class DefaultResourceResolver implements ResourceResolver { URL url = new URL(expression); resources.add(url); return true; - } catch (Exception e) { + } catch (IOException | RuntimeException e) { LOG.finest(() -> "Failed to load resource from file: " + expression); } return false;
