Skip to content

Commit 80b12da

Browse files
committed
Account for false positives only seen on GH CI
1 parent ee2243e commit 80b12da

File tree

2 files changed

+21
-34
lines changed

2 files changed

+21
-34
lines changed

src/conf/spotbugs-exclude-filter.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,39 @@
1919
xmlns="https://github.com/spotbugs/filter/3.0.0"
2020
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2121
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">
22-
2322
<Match>
2423
<Class name="org.apache.commons.text.ExtendedMessageFormat" />
2524
<Bug code="UR" />
2625
</Match>
27-
26+
<Match>
27+
<Class name="org.apache.commons.text.ExtendedMessageFormat" />
28+
<!-- False positives -->
29+
<!-- [lines 225-227] SF_SWITCH_FALLTHROUGH -->
30+
<!-- [lines 424-426] SF_SWITCH_FALLTHROUGH -->
31+
<Bug pattern="SF_SWITCH_FALLTHROUGH" />
32+
</Match>
2833
<Match>
2934
<!-- False positives in regard to Locale property exposing inner implementation
3035
details of class. However, Locale is not mutable and therefore safe in this context. -->
3136
<Class name="org.apache.commons.text.similarity.FuzzyScore" />
3237
<Bug code="EI,EI2" />
3338
</Match>
34-
3539
<Match>
3640
<Class name="org.apache.commons.text.StrTokenizer" />
3741
<Method name="clone" />
3842
<Bug code="CN" />
3943
</Match>
40-
4144
<Match>
4245
<Class name="org.apache.commons.text.StringTokenizer" />
4346
<Method name="clone" />
4447
<Bug code="CN" />
4548
</Match>
46-
4749
<!-- BiFunctionStringLookup#lookup catches NPE to return null -->
4850
<Match>
4951
<Class name="org.apache.commons.text.lookup.BiFunctionStringLookup" />
5052
<Method name="lookup" />
5153
<Bug pattern="DCN_NULLPOINTER_EXCEPTION" />
5254
</Match>
53-
5455
<!-- FunctionStringLookup#lookup catches NPE to return null -->
5556
<Match>
5657
<Class name="org.apache.commons.text.lookup.FunctionStringLookup" />

src/main/java/org/apache/commons/text/ExtendedMessageFormat.java

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,52 +135,42 @@ public ExtendedMessageFormat(final String pattern, final Locale locale) {
135135
* Constructs a new ExtendedMessageFormat.
136136
*
137137
* @param pattern the pattern to use, not null
138-
* @param locale the locale to use, not null
139-
* @param registry the registry of format factories, may be null
138+
* @param locale the locale to use, not null
139+
* @param registry the registry of format factories, may be null
140140
* @throws IllegalArgumentException in case of a bad pattern.
141141
*/
142-
public ExtendedMessageFormat(final String pattern,
143-
final Locale locale,
144-
final Map<String, ? extends FormatFactory> registry) {
142+
public ExtendedMessageFormat(final String pattern, final Locale locale, final Map<String, ? extends FormatFactory> registry) {
145143
super(EMPTY_PATTERN);
146144
setLocale(locale);
147-
this.registry = registry != null
148-
? Collections.unmodifiableMap(new HashMap<>(registry))
149-
: null;
145+
this.registry = registry != null ? Collections.unmodifiableMap(new HashMap<>(registry)) : null;
150146
applyPattern(pattern);
151147
}
152148

153149
/**
154150
* Constructs a new ExtendedMessageFormat for the default locale.
155151
*
156152
* @param pattern the pattern to use, not null
157-
* @param registry the registry of format factories, may be null
153+
* @param registry the registry of format factories, may be null
158154
* @throws IllegalArgumentException in case of a bad pattern.
159155
*/
160-
public ExtendedMessageFormat(final String pattern,
161-
final Map<String, ? extends FormatFactory> registry) {
156+
public ExtendedMessageFormat(final String pattern, final Map<String, ? extends FormatFactory> registry) {
162157
this(pattern, Locale.getDefault(Category.FORMAT), registry);
163158
}
164159

165160
/**
166-
* Consumes a quoted string, adding it to {@code appendTo} if
167-
* specified.
161+
* Consumes a quoted string, adding it to {@code appendTo} if specified.
168162
*
169-
* @param pattern pattern to parse
170-
* @param pos current parse position
163+
* @param pattern pattern to parse
164+
* @param pos current parse position
171165
* @param appendTo optional StringBuilder to append
172166
*/
173-
private void appendQuotedString(final String pattern, final ParsePosition pos,
174-
final StringBuilder appendTo) {
175-
assert pattern.toCharArray()[pos.getIndex()] == QUOTE
176-
: "Quoted string must start with quote character";
177-
167+
private void appendQuotedString(final String pattern, final ParsePosition pos, final StringBuilder appendTo) {
168+
assert pattern.toCharArray()[pos.getIndex()] == QUOTE : "Quoted string must start with quote character";
178169
// handle quote character at the beginning of the string
179170
if (appendTo != null) {
180171
appendTo.append(QUOTE);
181172
}
182173
next(pos);
183-
184174
final int start = pos.getIndex();
185175
final char[] c = pattern.toCharArray();
186176
for (int i = pos.getIndex(); i < pattern.length(); i++) {
@@ -195,8 +185,7 @@ private void appendQuotedString(final String pattern, final ParsePosition pos,
195185
next(pos);
196186
}
197187
}
198-
throw new IllegalArgumentException(
199-
"Unterminated quoted string at position " + start);
188+
throw new IllegalArgumentException("Unterminated quoted string at position " + start);
200189
}
201190

202191
/**
@@ -214,7 +203,6 @@ public final void applyPattern(final String pattern) {
214203
final ArrayList<Format> foundFormats = new ArrayList<>();
215204
final ArrayList<String> foundDescriptions = new ArrayList<>();
216205
final StringBuilder stripCustom = new StringBuilder(pattern.length());
217-
218206
final ParsePosition pos = new ParsePosition(0);
219207
final char[] c = pattern.toCharArray();
220208
int fmtCount = 0;
@@ -233,8 +221,7 @@ public final void applyPattern(final String pattern) {
233221
Format format = null;
234222
String formatDescription = null;
235223
if (c[pos.getIndex()] == START_FMT) {
236-
formatDescription = parseFormatDescription(pattern,
237-
next(pos));
224+
formatDescription = parseFormatDescription(pattern, next(pos));
238225
format = getFormat(formatDescription);
239226
if (format == null) {
240227
stripCustom.append(START_FMT).append(formatDescription);
@@ -249,8 +236,7 @@ public final void applyPattern(final String pattern) {
249236
throw new IllegalArgumentException("The validated expression is false");
250237
}
251238
if (c[pos.getIndex()] != END_FE) {
252-
throw new IllegalArgumentException(
253-
"Unreadable format element at position " + start);
239+
throw new IllegalArgumentException("Unreadable format element at position " + start);
254240
}
255241
//$FALL-THROUGH$
256242
default:

0 commit comments

Comments
 (0)