This is an automated email from the ASF dual-hosted git repository.
Claudenw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/creadur-rat.git
The following commit(s) were added to refs/heads/master by this push:
new 75efb86f RAT-566: fix some spotbugs issues in core (#688)
75efb86f is described below
commit 75efb86f49e029b09e3067a497aab5af7aa1e67a
Author: Claude Warren <[email protected]>
AuthorDate: Sun Jun 28 23:33:53 2026 +0200
RAT-566: fix some spotbugs issues in core (#688)
* fixed spotbugs issues
* added exception tests
* added license headers
---
.../org/apache/rat/ConfigurationException.java | 4 +--
.../src/main/java/org/apache/rat/Defaults.java | 3 +-
.../org/apache/rat/ImplementationException.java | 4 +--
.../license/SimplePatternBasedLicense.java | 2 ++
.../rat/analysis/matchers/SimpleTextMatcher.java | 7 ++--
.../configuration/builders/MatcherRefBuilder.java | 4 +++
.../java/org/apache/rat/header/HeaderMatcher.java | 2 ++
.../main/java/org/apache/rat/help/Licenses.java | 3 ++
.../apache/rat/ConfigurationExceptionTest.java} | 39 ++++++++++------------
.../apache/rat/ImplementationExceptionTest.java} | 39 ++++++++++------------
10 files changed, 58 insertions(+), 49 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);
diff --git
a/apache-rat-core/src/main/java/org/apache/rat/ConfigurationException.java
b/apache-rat-core/src/test/java/org/apache/rat/ConfigurationExceptionTest.java
similarity index 55%
copy from
apache-rat-core/src/main/java/org/apache/rat/ConfigurationException.java
copy to
apache-rat-core/src/test/java/org/apache/rat/ConfigurationExceptionTest.java
index d5add9fe..e94a20f0 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/ConfigurationException.java
+++
b/apache-rat-core/src/test/java/org/apache/rat/ConfigurationExceptionTest.java
@@ -7,7 +7,7 @@
* "License"); you may not use this file except in compliance *
* with the License. You may obtain a copy of the License at *
* *
- * http://www.apache.org/licenses/LICENSE-2.0 *
+ * https://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, *
* software distributed under the License is distributed on an *
@@ -18,30 +18,27 @@
*/
package org.apache.rat;
-/**
- * An exception thrown when there is an issue with the configuration.
- */
-public class ConfigurationException extends RuntimeException {
+import org.junit.jupiter.api.Test;
- private static final long serialVersionUID = 7257245932787579431L;
+import static org.assertj.core.api.Assertions.assertThat;
- public static ConfigurationException from(final Exception e) {
- if (e instanceof ConfigurationException) {
- return (ConfigurationException) e;
- }
- return new ConfigurationException(e);
- }
+class ConfigurationExceptionTest {
- public ConfigurationException(final String message, final Throwable cause)
{
- super(message, cause);
- }
+ @Test
+ void fromTest() {
+ RuntimeException runTime = new RuntimeException();
+ assertThat(ConfigurationException.from(runTime))
+ .isInstanceOf(ConfigurationException.class)
+ .hasCause(runTime);
- public ConfigurationException(final String message) {
- super(message);
- }
+ Exception ex = new Exception();
+ assertThat(ConfigurationException.from(ex))
+ .isInstanceOf(ConfigurationException.class)
+ .hasCause(ex);
- public ConfigurationException(final Throwable cause) {
- super(cause);
+ ex = new ConfigurationException("yee haw");
+ assertThat(ConfigurationException.from(ex))
+ .isInstanceOf(ConfigurationException.class)
+ .isEqualTo(ex);
}
-
}
diff --git
a/apache-rat-core/src/main/java/org/apache/rat/ConfigurationException.java
b/apache-rat-core/src/test/java/org/apache/rat/ImplementationExceptionTest.java
similarity index 54%
copy from
apache-rat-core/src/main/java/org/apache/rat/ConfigurationException.java
copy to
apache-rat-core/src/test/java/org/apache/rat/ImplementationExceptionTest.java
index d5add9fe..74771ed5 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/ConfigurationException.java
+++
b/apache-rat-core/src/test/java/org/apache/rat/ImplementationExceptionTest.java
@@ -7,7 +7,7 @@
* "License"); you may not use this file except in compliance *
* with the License. You may obtain a copy of the License at *
* *
- * http://www.apache.org/licenses/LICENSE-2.0 *
+ * https://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, *
* software distributed under the License is distributed on an *
@@ -18,30 +18,27 @@
*/
package org.apache.rat;
-/**
- * An exception thrown when there is an issue with the configuration.
- */
-public class ConfigurationException extends RuntimeException {
+import org.junit.jupiter.api.Test;
- private static final long serialVersionUID = 7257245932787579431L;
+import static org.assertj.core.api.Assertions.assertThat;
- public static ConfigurationException from(final Exception e) {
- if (e instanceof ConfigurationException) {
- return (ConfigurationException) e;
- }
- return new ConfigurationException(e);
- }
+class ImplementationExceptionTest {
- public ConfigurationException(final String message, final Throwable cause)
{
- super(message, cause);
- }
+ @Test
+ void fromTest() {
+ RuntimeException runTime = new RuntimeException();
+ assertThat(ImplementationException.makeInstance(runTime))
+ .isInstanceOf(ImplementationException.class)
+ .hasCause(runTime);
- public ConfigurationException(final String message) {
- super(message);
- }
+ Exception ex = new Exception();
+ assertThat(ImplementationException.makeInstance(ex))
+ .isInstanceOf(ImplementationException.class)
+ .hasCause(ex);
- public ConfigurationException(final Throwable cause) {
- super(cause);
+ ex = new ImplementationException("yee haw");
+ assertThat(ImplementationException.makeInstance(ex))
+ .isInstanceOf(ImplementationException.class)
+ .isEqualTo(ex);
}
-
}