You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/08/24 20:20:14 UTC
(commons-text) 01/02: Account for false positives only seen on GH CI
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git
commit 80b12daa94162ee828f3e450dc0f431a0bb1888e
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Aug 24 16:19:21 2025 -0400
Account for false positives only seen on GH CI
---
src/conf/spotbugs-exclude-filter.xml | 13 +++----
.../apache/commons/text/ExtendedMessageFormat.java | 42 ++++++++--------------
2 files changed, 21 insertions(+), 34 deletions(-)
diff --git a/src/conf/spotbugs-exclude-filter.xml b/src/conf/spotbugs-exclude-filter.xml
index 2656019b..d918d9f0 100644
--- a/src/conf/spotbugs-exclude-filter.xml
+++ b/src/conf/spotbugs-exclude-filter.xml
@@ -19,38 +19,39 @@
xmlns="https://github.com/spotbugs/filter/3.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">
-
<Match>
<Class name="org.apache.commons.text.ExtendedMessageFormat" />
<Bug code="UR" />
</Match>
-
+ <Match>
+ <Class name="org.apache.commons.text.ExtendedMessageFormat" />
+ <!-- False positives -->
+ <!-- [lines 225-227] SF_SWITCH_FALLTHROUGH -->
+ <!-- [lines 424-426] SF_SWITCH_FALLTHROUGH -->
+ <Bug pattern="SF_SWITCH_FALLTHROUGH" />
+ </Match>
<Match>
<!-- False positives in regard to Locale property exposing inner implementation
details of class. However, Locale is not mutable and therefore safe in this context. -->
<Class name="org.apache.commons.text.similarity.FuzzyScore" />
<Bug code="EI,EI2" />
</Match>
-
<Match>
<Class name="org.apache.commons.text.StrTokenizer" />
<Method name="clone" />
<Bug code="CN" />
</Match>
-
<Match>
<Class name="org.apache.commons.text.StringTokenizer" />
<Method name="clone" />
<Bug code="CN" />
</Match>
-
<!-- BiFunctionStringLookup#lookup catches NPE to return null -->
<Match>
<Class name="org.apache.commons.text.lookup.BiFunctionStringLookup" />
<Method name="lookup" />
<Bug pattern="DCN_NULLPOINTER_EXCEPTION" />
</Match>
-
<!-- FunctionStringLookup#lookup catches NPE to return null -->
<Match>
<Class name="org.apache.commons.text.lookup.FunctionStringLookup" />
diff --git a/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java b/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java
index 5cc88e3c..e9554900 100644
--- a/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java
+++ b/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java
@@ -135,18 +135,14 @@ public class ExtendedMessageFormat extends MessageFormat {
* Constructs a new ExtendedMessageFormat.
*
* @param pattern the pattern to use, not null
- * @param locale the locale to use, not null
- * @param registry the registry of format factories, may be null
+ * @param locale the locale to use, not null
+ * @param registry the registry of format factories, may be null
* @throws IllegalArgumentException in case of a bad pattern.
*/
- public ExtendedMessageFormat(final String pattern,
- final Locale locale,
- final Map<String, ? extends FormatFactory> registry) {
+ public ExtendedMessageFormat(final String pattern, final Locale locale, final Map<String, ? extends FormatFactory> registry) {
super(EMPTY_PATTERN);
setLocale(locale);
- this.registry = registry != null
- ? Collections.unmodifiableMap(new HashMap<>(registry))
- : null;
+ this.registry = registry != null ? Collections.unmodifiableMap(new HashMap<>(registry)) : null;
applyPattern(pattern);
}
@@ -154,33 +150,27 @@ public class ExtendedMessageFormat extends MessageFormat {
* Constructs a new ExtendedMessageFormat for the default locale.
*
* @param pattern the pattern to use, not null
- * @param registry the registry of format factories, may be null
+ * @param registry the registry of format factories, may be null
* @throws IllegalArgumentException in case of a bad pattern.
*/
- public ExtendedMessageFormat(final String pattern,
- final Map<String, ? extends FormatFactory> registry) {
+ public ExtendedMessageFormat(final String pattern, final Map<String, ? extends FormatFactory> registry) {
this(pattern, Locale.getDefault(Category.FORMAT), registry);
}
/**
- * Consumes a quoted string, adding it to {@code appendTo} if
- * specified.
+ * Consumes a quoted string, adding it to {@code appendTo} if specified.
*
- * @param pattern pattern to parse
- * @param pos current parse position
+ * @param pattern pattern to parse
+ * @param pos current parse position
* @param appendTo optional StringBuilder to append
*/
- private void appendQuotedString(final String pattern, final ParsePosition pos,
- final StringBuilder appendTo) {
- assert pattern.toCharArray()[pos.getIndex()] == QUOTE
- : "Quoted string must start with quote character";
-
+ private void appendQuotedString(final String pattern, final ParsePosition pos, final StringBuilder appendTo) {
+ assert pattern.toCharArray()[pos.getIndex()] == QUOTE : "Quoted string must start with quote character";
// handle quote character at the beginning of the string
if (appendTo != null) {
appendTo.append(QUOTE);
}
next(pos);
-
final int start = pos.getIndex();
final char[] c = pattern.toCharArray();
for (int i = pos.getIndex(); i < pattern.length(); i++) {
@@ -195,8 +185,7 @@ public class ExtendedMessageFormat extends MessageFormat {
next(pos);
}
}
- throw new IllegalArgumentException(
- "Unterminated quoted string at position " + start);
+ throw new IllegalArgumentException("Unterminated quoted string at position " + start);
}
/**
@@ -214,7 +203,6 @@ public class ExtendedMessageFormat extends MessageFormat {
final ArrayList<Format> foundFormats = new ArrayList<>();
final ArrayList<String> foundDescriptions = new ArrayList<>();
final StringBuilder stripCustom = new StringBuilder(pattern.length());
-
final ParsePosition pos = new ParsePosition(0);
final char[] c = pattern.toCharArray();
int fmtCount = 0;
@@ -233,8 +221,7 @@ public class ExtendedMessageFormat extends MessageFormat {
Format format = null;
String formatDescription = null;
if (c[pos.getIndex()] == START_FMT) {
- formatDescription = parseFormatDescription(pattern,
- next(pos));
+ formatDescription = parseFormatDescription(pattern, next(pos));
format = getFormat(formatDescription);
if (format == null) {
stripCustom.append(START_FMT).append(formatDescription);
@@ -249,8 +236,7 @@ public class ExtendedMessageFormat extends MessageFormat {
throw new IllegalArgumentException("The validated expression is false");
}
if (c[pos.getIndex()] != END_FE) {
- throw new IllegalArgumentException(
- "Unreadable format element at position " + start);
+ throw new IllegalArgumentException("Unreadable format element at position " + start);
}
//$FALL-THROUGH$
default: