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-lang.git
The following commit(s) were added to refs/heads/master by this push:
new 5bcedccec Fix NullPointerException in
ReflectionDiffBuilder.getExcludeFieldNames() when instance created with
ReflectionDiffBuilder.ReflectionDiffBuilder(T, T, ToStringStyle)
5bcedccec is described below
commit 5bcedccec3ed93586947a5df0d49775aee7a37c7
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Nov 26 18:51:15 2025 +0000
Fix NullPointerException in ReflectionDiffBuilder.getExcludeFieldNames()
when instance created with
ReflectionDiffBuilder.ReflectionDiffBuilder(T, T, ToStringStyle)
---
src/changes/changes.xml | 1 +
.../org/apache/commons/lang3/builder/ReflectionDiffBuilder.java | 9 +++++----
.../apache/commons/lang3/builder/ReflectionDiffBuilderTest.java | 8 ++++++++
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 527aa1c8c..e3de10be4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -64,6 +64,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary
Gregory">Fix Apache RAT plugin console warnings.</action>
<action issue="LANG-1793" type="fix" dev="ggregory" due-to="IcoreE">Fix
Javadoc description in CharUtils.isAsciiAlphanumeric() #1501.</action>
<action issue="LANG-1794" type="fix" dev="ggregory" due-to="IcoreE">Fix
Javadoc for RandomUtils.secure(), it incorrectly mentions
securerandom.strongAlgorithms #1503.</action>
+ <action type="fix" dev="ggregory" due-to="Gary
Gregory">Fix NullPointerException in
ReflectionDiffBuilder.getExcludeFieldNames() when instance created with
ReflectionDiffBuilder.ReflectionDiffBuilder(T, T, ToStringStyle).</action>
<!-- ADD -->
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary
Gregory, Dependabot">Bump org.apache.commons:commons-parent from 92 to 93
#1498.</action>
diff --git
a/src/main/java/org/apache/commons/lang3/builder/ReflectionDiffBuilder.java
b/src/main/java/org/apache/commons/lang3/builder/ReflectionDiffBuilder.java
index 9bd8963b4..42e2cc585 100644
--- a/src/main/java/org/apache/commons/lang3/builder/ReflectionDiffBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/ReflectionDiffBuilder.java
@@ -19,6 +19,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
+import java.util.Objects;
import org.apache.commons.lang3.ArraySorter;
import org.apache.commons.lang3.ArrayUtils;
@@ -155,7 +156,7 @@ private static String[] toExcludeFieldNames(final String[]
excludeFieldNames) {
private ReflectionDiffBuilder(final DiffBuilder<T> diffBuilder, final
String[] excludeFieldNames) {
this.diffBuilder = diffBuilder;
- this.excludeFieldNames = excludeFieldNames;
+ this.excludeFieldNames = Objects.requireNonNull(excludeFieldNames);
}
/**
@@ -174,7 +175,7 @@ private ReflectionDiffBuilder(final DiffBuilder<T>
diffBuilder, final String[] e
*/
@Deprecated
public ReflectionDiffBuilder(final T left, final T right, final
ToStringStyle style) {
-
this(DiffBuilder.<T>builder().setLeft(left).setRight(right).setStyle(style).build(),
null);
+
this(DiffBuilder.<T>builder().setLeft(left).setRight(right).setStyle(style).build(),
ArrayUtils.EMPTY_STRING_ARRAY);
}
private boolean accept(final Field field) {
@@ -187,7 +188,7 @@ private boolean accept(final Field field) {
if (Modifier.isStatic(field.getModifiers())) {
return false;
}
- if (this.excludeFieldNames != null &&
Arrays.binarySearch(this.excludeFieldNames, field.getName()) >= 0) {
+ if (excludeFieldNames != null &&
Arrays.binarySearch(excludeFieldNames, field.getName()) >= 0) {
// Reject fields from the getExcludeFieldNames list.
return false;
}
@@ -236,7 +237,7 @@ public DiffResult<T> build() {
* @since 3.13.0
*/
public String[] getExcludeFieldNames() {
- return this.excludeFieldNames.clone();
+ return excludeFieldNames.clone();
}
private T getLeft() {
diff --git
a/src/test/java/org/apache/commons/lang3/builder/ReflectionDiffBuilderTest.java
b/src/test/java/org/apache/commons/lang3/builder/ReflectionDiffBuilderTest.java
index 7f17f2107..c21764057 100644
---
a/src/test/java/org/apache/commons/lang3/builder/ReflectionDiffBuilderTest.java
+++
b/src/test/java/org/apache/commons/lang3/builder/ReflectionDiffBuilderTest.java
@@ -146,6 +146,14 @@ void testDifferenceInInherited_field() {
assertEquals(1, list.getNumberOfDiffs());
}
+ @Test
+ void testGetExcludeFieldNamesEmpty() {
+ final ReflectionDiffBuilder reflectionDiffBuilder = new
ReflectionDiffBuilder(new TypeTestClass(), new TypeTestChildClass(),
SHORT_STYLE);
+ final String[] excludeFieldNames =
reflectionDiffBuilder.getExcludeFieldNames();
+ assertNotNull(excludeFieldNames);
+ assertEquals(0, excludeFieldNames.length);
+ }
+
@Test
void testGetExcludeFieldNamesWithNullExcludedFieldNames() {
// @formatter:off