This is an automated email from the ASF dual-hosted git repository. Claudenw pushed a commit to branch fix-spotbugs-in-core-pt1 in repository https://gitbox.apache.org/repos/asf/creadur-rat.git
commit dc95eeb1443da6a0e738390786ddc3a8347ed175 Author: Claude Warren <[email protected]> AuthorDate: Sun Jun 28 09:17:31 2026 +0100 fixed spotbugs issues --- .../src/main/java/org/apache/rat/ConfigurationException.java | 4 ++-- apache-rat-core/src/main/java/org/apache/rat/Defaults.java | 3 ++- .../src/main/java/org/apache/rat/ImplementationException.java | 4 ++-- .../org/apache/rat/analysis/license/SimplePatternBasedLicense.java | 2 ++ .../java/org/apache/rat/analysis/matchers/SimpleTextMatcher.java | 7 +++++-- .../org/apache/rat/configuration/builders/MatcherRefBuilder.java | 4 ++++ .../src/main/java/org/apache/rat/header/HeaderMatcher.java | 2 ++ apache-rat-core/src/main/java/org/apache/rat/help/Licenses.java | 3 +++ 8 files changed, 22 insertions(+), 7 deletions(-) diff --git a/apache-rat-core/src/main/java/org/apache/rat/ConfigurationException.java b/apache-rat-core/src/main/java/org/apache/rat/ConfigurationException.java index d5add9fe..f8a94cb2 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/ConfigurationException.java +++ b/apache-rat-core/src/main/java/org/apache/rat/ConfigurationException.java @@ -26,8 +26,8 @@ public class ConfigurationException extends RuntimeException { private static final long serialVersionUID = 7257245932787579431L; public static ConfigurationException from(final Exception e) { - if (e instanceof ConfigurationException) { - return (ConfigurationException) e; + if (e instanceof ConfigurationException exists) { + return exists; } return new ConfigurationException(e); } diff --git a/apache-rat-core/src/main/java/org/apache/rat/Defaults.java b/apache-rat-core/src/main/java/org/apache/rat/Defaults.java index 87c7ed8d..16850e7b 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/Defaults.java +++ b/apache-rat-core/src/main/java/org/apache/rat/Defaults.java @@ -49,7 +49,8 @@ public final class Defaults { /** The default configuration file from the package. */ private static final URI DEFAULT_CONFIG_URI; /** The path to the default configuration file. */ - private static final String DEFAULT_CONFIG_PATH = "/org/apache/rat/default.xml"; + // sonar wants this to be configurable. + private static final String DEFAULT_CONFIG_PATH = "/org/apache/rat/default.xml"; // NOSONAR /** The default ARCHIVES processing style. */ public static final ReportConfiguration.Processing ARCHIVE_PROCESSING = ReportConfiguration.Processing.NOTIFICATION; /** The default STANDARD processing style. */ diff --git a/apache-rat-core/src/main/java/org/apache/rat/ImplementationException.java b/apache-rat-core/src/main/java/org/apache/rat/ImplementationException.java index 76bd2f7c..17fc4724 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/ImplementationException.java +++ b/apache-rat-core/src/main/java/org/apache/rat/ImplementationException.java @@ -26,8 +26,8 @@ public class ImplementationException extends RuntimeException { private static final long serialVersionUID = 7257245932787579431L; public static ImplementationException makeInstance(final Exception e) { - if (e instanceof ImplementationException) { - return (ImplementationException) e; + if (e instanceof ImplementationException exists) { + return exists; } return new ImplementationException(e); } diff --git a/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java b/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java index 21a3230e..4032d01f 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java +++ b/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java @@ -20,6 +20,7 @@ package org.apache.rat.analysis.license; import java.util.Arrays; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.rat.DeprecationReporter; import org.apache.rat.configuration.builders.AbstractBuilder; import org.apache.rat.configuration.builders.AnyBuilder; @@ -31,6 +32,7 @@ import org.apache.rat.license.ILicense; * @since Rat 0.8 * @deprecated Use new configuration options */ +@SuppressFBWarnings("EI_EXPOSE_REP2") @Deprecated // Since 0.16 @DeprecationReporter.Info(since = "0.16", forRemoval = true, use = "new configuration options") public class SimplePatternBasedLicense extends BaseLicense { diff --git a/apache-rat-core/src/main/java/org/apache/rat/analysis/matchers/SimpleTextMatcher.java b/apache-rat-core/src/main/java/org/apache/rat/analysis/matchers/SimpleTextMatcher.java index c77ddf09..2a5d46b5 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/analysis/matchers/SimpleTextMatcher.java +++ b/apache-rat-core/src/main/java/org/apache/rat/analysis/matchers/SimpleTextMatcher.java @@ -23,6 +23,8 @@ import org.apache.rat.analysis.IHeaders; import org.apache.rat.config.parameters.ComponentType; import org.apache.rat.config.parameters.ConfigComponent; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + /** * A simple text matching IHeaderMatcher implementation. */ @@ -44,11 +46,12 @@ public class SimpleTextMatcher extends AbstractHeaderMatcher { this(null, simpleText); } + // no sonar and supress FI_USELESS because this is how we ensure that the finalize bug does not bite us + @SuppressFBWarnings("FI_USELESS") @Override protected final void finalize() throws Throwable { // NOSONAR - // no sonar because this is how we ensure that the finalize bug does not bite us + // finalizer attack remediation. super.finalize(); // NOSONAR - // finalizer attack remediation. } /** diff --git a/apache-rat-core/src/main/java/org/apache/rat/configuration/builders/MatcherRefBuilder.java b/apache-rat-core/src/main/java/org/apache/rat/configuration/builders/MatcherRefBuilder.java index 68598d4c..1662220f 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/configuration/builders/MatcherRefBuilder.java +++ b/apache-rat-core/src/main/java/org/apache/rat/configuration/builders/MatcherRefBuilder.java @@ -27,6 +27,8 @@ import org.apache.rat.config.parameters.ComponentType; import org.apache.rat.config.parameters.ConfigComponent; import org.apache.rat.config.parameters.MatcherBuilder; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + /** * A reference matching Matcher builder. * <p> @@ -62,6 +64,7 @@ public class MatcherRefBuilder extends AbstractBuilder { * @param matchers the Map of ids to instances. * @return this builder for chaining. */ + @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "Expected external update of matchers.") public MatcherRefBuilder setMatcherMap(final Map<String, IHeaderMatcher> matchers) { // this method is called by reflection this.matchers = matchers; @@ -109,6 +112,7 @@ public class MatcherRefBuilder extends AbstractBuilder { * @param proxyId the id of the matcher to find. * @param matchers a mapping of matchers that have been found. */ + @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "Expected external update of matchers.") public IHeaderMatcherProxy(final String proxyId, final Map<String, IHeaderMatcher> matchers) { this.proxyId = proxyId; this.matchers = matchers; diff --git a/apache-rat-core/src/main/java/org/apache/rat/header/HeaderMatcher.java b/apache-rat-core/src/main/java/org/apache/rat/header/HeaderMatcher.java index 89b71b0a..7f05afa3 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/header/HeaderMatcher.java +++ b/apache-rat-core/src/main/java/org/apache/rat/header/HeaderMatcher.java @@ -18,6 +18,7 @@ */ package org.apache.rat.header; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.rat.DeprecationReporter; import java.io.IOException; @@ -35,6 +36,7 @@ import java.util.regex.Pattern; * <p><strong>Note:</strong> use only from a single thread.</p> * */ +@SuppressFBWarnings("EI_EXPOSE_REP2") @Deprecated // since 0.17 @DeprecationReporter.Info(since = "0.17", forRemoval = true) public class HeaderMatcher { diff --git a/apache-rat-core/src/main/java/org/apache/rat/help/Licenses.java b/apache-rat-core/src/main/java/org/apache/rat/help/Licenses.java index 0277186b..bac55af5 100644 --- a/apache-rat-core/src/main/java/org/apache/rat/help/Licenses.java +++ b/apache-rat-core/src/main/java/org/apache/rat/help/Licenses.java @@ -43,6 +43,8 @@ import org.apache.rat.license.ILicense; import org.apache.rat.license.ILicenseFamily; import org.apache.rat.license.LicenseSetFactory.LicenseFilter; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import static java.lang.String.format; /** @@ -64,6 +66,7 @@ public final class Licenses extends AbstractHelp { * @param config The configuration that contains the license information. * @param writer the writer to write the report to. */ + @SuppressFBWarnings("EI_EXPOSE_REP2") public Licenses(final ReportConfiguration config, final Writer writer) { this.config = config; this.licenses = config.getLicenses(LicenseFilter.ALL);
