Skip to content

Commit c64d702

Browse files
authored
Merge branch 'master' into fb_jpms
2 parents f20639a + d2f8cac commit c64d702

File tree

12 files changed

+502
-518
lines changed

12 files changed

+502
-518
lines changed

pom.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585
<dependency>
8686
<groupId>org.apache.commons</groupId>
8787
<artifactId>commons-text</artifactId>
88-
<version>1.12.0</version>
89-
<scope>provided</scope>
88+
<version>${commons.text.version}</version>
89+
<scope>test</scope>
9090
</dependency>
9191
<dependency>
9292
<groupId>org.openjdk.jmh</groupId>
@@ -174,6 +174,7 @@
174174
<commons.jacoco.branchRatio>0.92</commons.jacoco.branchRatio>
175175
<commons.jacoco.lineRatio>0.95</commons.jacoco.lineRatio>
176176
<commons.jacoco.complexityRatio>0.90</commons.jacoco.complexityRatio>
177+
<commons.text.version>1.12.0</commons.text.version>
177178
</properties>
178179

179180
<build>
@@ -226,6 +227,13 @@
226227
</manifest>
227228
</archive>
228229
<doclint>all</doclint>
230+
<additionalDependencies>
231+
<additionalDependency>
232+
<groupId>org.apache.commons</groupId>
233+
<artifactId>commons-text</artifactId>
234+
<version>${commons.text.version}</version>
235+
</additionalDependency>
236+
</additionalDependencies>
229237
</configuration>
230238
<executions>
231239
<execution>

src/changes/changes.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ The <action> type attribute can be add,update,fix,remove.
6868
<action type="fix" dev="ggregory" due-to="Gary Gregory">Make Failable.run(FailableRunnable) null-safe.</action>
6969
<action type="fix" dev="ggregory" due-to="Gary Gregory">Make Failable.accept(*) null-safe.</action>
7070
<action type="fix" dev="ggregory" due-to="maxxedev, Piotr P. Karwasz, Gary Gregory">Improve container detection by mimicking systemd #1323.</action>
71+
<action type="fix" dev="ggregory" due-to="Gary Gregory">Make LangCollectors.collect(...) null-safe.</action>
72+
<action type="fix" dev="ggregory" due-to="Gary Gregory">Make LangCollectors.collect(...) null-safe.</action>
73+
<action type="fix" dev="ggregory" due-to="IBue, Gary Gregory">Fix names of UTF-16 surrogate character test fixture constants, see also #1326.</action>
74+
<action type="fix" dev="ggregory" due-to="Gary Gregory">Moditect plugin generates split package warnings.</action>
7175
<!-- ADD -->
7276
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Strings and refactor StringUtils.</action>
7377
<action issue="LANG-1747" type="add" dev="ggregory" due-to="Oliver B. Fischer, Gary Gregory">Add StopWatch.run([Failable]Runnable) and get([Failable]Supplier).</action>

src/main/java/org/apache/commons/lang3/LocaleUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ static class SyncAvoid {
6060

6161
/**
6262
* The undetermined language {@value}.
63+
* <p>
64+
* If a language is empty, or not <em>well-formed</am> (for example "a" or "e2"), {@link Locale#toLanguageTag()} will return {@code "und"} (Undetermined).
65+
* </p>
66+
*
67+
* @see Locale#toLanguageTag()
6368
*/
6469
private static final String UNDETERMINED = "und";
6570

src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java

Lines changed: 38 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -150,162 +150,62 @@ private static final class JsonToStringStyle extends ToStringStyle {
150150
}
151151

152152
@Override
153-
public void append(final StringBuffer buffer, final String fieldName,
154-
final boolean[] array, final Boolean fullDetail) {
155-
156-
if (fieldName == null) {
157-
throw new UnsupportedOperationException(
158-
"Field names are mandatory when using JsonToStringStyle");
159-
}
160-
if (!isFullDetail(fullDetail)) {
161-
throw new UnsupportedOperationException(
162-
"FullDetail must be true when using JsonToStringStyle");
163-
}
164-
153+
public void append(final StringBuffer buffer, final String fieldName, final boolean[] array, final Boolean fullDetail) {
154+
checkAppendInput(fieldName, fullDetail);
165155
super.append(buffer, fieldName, array, fullDetail);
166156
}
167157

168158
@Override
169-
public void append(final StringBuffer buffer, final String fieldName, final byte[] array,
170-
final Boolean fullDetail) {
171-
172-
if (fieldName == null) {
173-
throw new UnsupportedOperationException(
174-
"Field names are mandatory when using JsonToStringStyle");
175-
}
176-
if (!isFullDetail(fullDetail)) {
177-
throw new UnsupportedOperationException(
178-
"FullDetail must be true when using JsonToStringStyle");
179-
}
180-
159+
public void append(final StringBuffer buffer, final String fieldName, final byte[] array, final Boolean fullDetail) {
160+
checkAppendInput(fieldName, fullDetail);
181161
super.append(buffer, fieldName, array, fullDetail);
182162
}
183163

184164
@Override
185-
public void append(final StringBuffer buffer, final String fieldName, final char[] array,
186-
final Boolean fullDetail) {
187-
188-
if (fieldName == null) {
189-
throw new UnsupportedOperationException(
190-
"Field names are mandatory when using JsonToStringStyle");
191-
}
192-
if (!isFullDetail(fullDetail)) {
193-
throw new UnsupportedOperationException(
194-
"FullDetail must be true when using JsonToStringStyle");
195-
}
196-
165+
public void append(final StringBuffer buffer, final String fieldName, final char[] array, final Boolean fullDetail) {
166+
checkAppendInput(fieldName, fullDetail);
197167
super.append(buffer, fieldName, array, fullDetail);
198168
}
199169

200170
@Override
201-
public void append(final StringBuffer buffer, final String fieldName,
202-
final double[] array, final Boolean fullDetail) {
203-
204-
if (fieldName == null) {
205-
throw new UnsupportedOperationException(
206-
"Field names are mandatory when using JsonToStringStyle");
207-
}
208-
if (!isFullDetail(fullDetail)) {
209-
throw new UnsupportedOperationException(
210-
"FullDetail must be true when using JsonToStringStyle");
211-
}
212-
171+
public void append(final StringBuffer buffer, final String fieldName, final double[] array, final Boolean fullDetail) {
172+
checkAppendInput(fieldName, fullDetail);
213173
super.append(buffer, fieldName, array, fullDetail);
214174
}
215175

216176
@Override
217-
public void append(final StringBuffer buffer, final String fieldName,
218-
final float[] array, final Boolean fullDetail) {
219-
220-
if (fieldName == null) {
221-
throw new UnsupportedOperationException(
222-
"Field names are mandatory when using JsonToStringStyle");
223-
}
224-
if (!isFullDetail(fullDetail)) {
225-
throw new UnsupportedOperationException(
226-
"FullDetail must be true when using JsonToStringStyle");
227-
}
228-
177+
public void append(final StringBuffer buffer, final String fieldName, final float[] array, final Boolean fullDetail) {
178+
checkAppendInput(fieldName, fullDetail);
229179
super.append(buffer, fieldName, array, fullDetail);
230180
}
231181

232182
@Override
233-
public void append(final StringBuffer buffer, final String fieldName, final int[] array,
234-
final Boolean fullDetail) {
235-
236-
if (fieldName == null) {
237-
throw new UnsupportedOperationException(
238-
"Field names are mandatory when using JsonToStringStyle");
239-
}
240-
if (!isFullDetail(fullDetail)) {
241-
throw new UnsupportedOperationException(
242-
"FullDetail must be true when using JsonToStringStyle");
243-
}
244-
183+
public void append(final StringBuffer buffer, final String fieldName, final int[] array, final Boolean fullDetail) {
184+
checkAppendInput(fieldName, fullDetail);
245185
super.append(buffer, fieldName, array, fullDetail);
246186
}
247187

248188
@Override
249-
public void append(final StringBuffer buffer, final String fieldName, final long[] array,
250-
final Boolean fullDetail) {
251-
252-
if (fieldName == null) {
253-
throw new UnsupportedOperationException(
254-
"Field names are mandatory when using JsonToStringStyle");
255-
}
256-
if (!isFullDetail(fullDetail)) {
257-
throw new UnsupportedOperationException(
258-
"FullDetail must be true when using JsonToStringStyle");
259-
}
260-
189+
public void append(final StringBuffer buffer, final String fieldName, final long[] array, final Boolean fullDetail) {
190+
checkAppendInput(fieldName, fullDetail);
261191
super.append(buffer, fieldName, array, fullDetail);
262192
}
263193

264194
@Override
265-
public void append(final StringBuffer buffer, final String fieldName, final Object value,
266-
final Boolean fullDetail) {
267-
268-
if (fieldName == null) {
269-
throw new UnsupportedOperationException(
270-
"Field names are mandatory when using JsonToStringStyle");
271-
}
272-
if (!isFullDetail(fullDetail)) {
273-
throw new UnsupportedOperationException(
274-
"FullDetail must be true when using JsonToStringStyle");
275-
}
276-
195+
public void append(final StringBuffer buffer, final String fieldName, final Object value, final Boolean fullDetail) {
196+
checkAppendInput(fieldName, fullDetail);
277197
super.append(buffer, fieldName, value, fullDetail);
278198
}
279199

280200
@Override
281-
public void append(final StringBuffer buffer, final String fieldName,
282-
final Object[] array, final Boolean fullDetail) {
283-
284-
if (fieldName == null) {
285-
throw new UnsupportedOperationException(
286-
"Field names are mandatory when using JsonToStringStyle");
287-
}
288-
if (!isFullDetail(fullDetail)) {
289-
throw new UnsupportedOperationException(
290-
"FullDetail must be true when using JsonToStringStyle");
291-
}
292-
201+
public void append(final StringBuffer buffer, final String fieldName, final Object[] array, final Boolean fullDetail) {
202+
checkAppendInput(fieldName, fullDetail);
293203
super.append(buffer, fieldName, array, fullDetail);
294204
}
295205

296206
@Override
297-
public void append(final StringBuffer buffer, final String fieldName,
298-
final short[] array, final Boolean fullDetail) {
299-
300-
if (fieldName == null) {
301-
throw new UnsupportedOperationException(
302-
"Field names are mandatory when using JsonToStringStyle");
303-
}
304-
if (!isFullDetail(fullDetail)) {
305-
throw new UnsupportedOperationException(
306-
"FullDetail must be true when using JsonToStringStyle");
307-
}
308-
207+
public void append(final StringBuffer buffer, final String fieldName, final short[] array, final Boolean fullDetail) {
208+
checkAppendInput(fieldName, fullDetail);
309209
super.append(buffer, fieldName, array, fullDetail);
310210
}
311211

@@ -325,7 +225,6 @@ protected void appendDetail(final StringBuffer buffer, final String fieldName, f
325225
buffer.append(getArrayEnd());
326226
return;
327227
}
328-
329228
buffer.append(coll);
330229
}
331230

@@ -390,10 +289,7 @@ protected void appendDetail(final StringBuffer buffer, final String fieldName, f
390289
@Override
391290
protected void appendFieldStart(final StringBuffer buffer, final String fieldName) {
392291

393-
if (fieldName == null) {
394-
throw new UnsupportedOperationException(
395-
"Field names are mandatory when using JsonToStringStyle");
396-
}
292+
checkFieldName(fieldName);
397293

398294
super.appendFieldStart(buffer, FIELD_NAME_QUOTE + StringEscapeUtils.escapeJson(fieldName)
399295
+ FIELD_NAME_QUOTE);
@@ -409,6 +305,23 @@ private void appendValueAsString(final StringBuffer buffer, final String value)
409305
buffer.append('"').append(StringEscapeUtils.escapeJson(value)).append('"');
410306
}
411307

308+
private void checkAppendInput(final String fieldName, final Boolean fullDetail) {
309+
checkFieldName(fieldName);
310+
checkIsFullDetail(fullDetail);
311+
}
312+
313+
private void checkFieldName(final String fieldName) {
314+
if (fieldName == null) {
315+
throw new UnsupportedOperationException("Field names are mandatory when using JsonToStringStyle");
316+
}
317+
}
318+
319+
private void checkIsFullDetail(final Boolean fullDetail) {
320+
if (!isFullDetail(fullDetail)) {
321+
throw new UnsupportedOperationException("FullDetail must be true when using JsonToStringStyle");
322+
}
323+
}
324+
412325
private boolean isJsonArray(final String valueAsString) {
413326
return valueAsString.startsWith(getArrayStart())
414327
&& valueAsString.endsWith(getArrayEnd());

src/main/java/org/apache/commons/lang3/stream/LangCollectors.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,16 @@ public Supplier<A> supplier() {
100100
* @param <R> the type of the result.
101101
* @param <A> the intermediate accumulation type of the {@code Collector}.
102102
* @param collector the {@code Collector} describing the reduction.
103-
* @param array The array, assumed to be unmodified during use.
103+
* @param array The array, assumed to be unmodified during use, a null array treated as an empty array.
104104
* @return the result of the reduction
105105
* @see Stream#collect(Collector)
106106
* @see Arrays#stream(Object[])
107107
* @see Collectors
108108
* @since 3.16.0
109109
*/
110+
@SafeVarargs
110111
public static <T, R, A> R collect(final Collector<? super T, A, R> collector, final T... array) {
111-
return Arrays.stream(array).collect(collector);
112+
return Streams.of(array).collect(collector);
112113
}
113114

114115
/**

0 commit comments

Comments
 (0)