From b7b52fc506ca531ce97c936b4b6d70f72a1125d3 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 12 May 2024 15:42:37 -0400 Subject: [PATCH] Internal refactoring --- src/changes/changes.xml | 1 + src/main/java/org/apache/commons/lang3/ObjectUtils.java | 2 +- src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 11a977dbc..11d055960 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -128,6 +128,7 @@ The type attribute can be add,update,fix,remove. Deprecate SystemUtils.getUserName(String) in favor of SystemProperties.getUserName(Supplier). Make LockVisitor.acceptReadLocked(FailableConsumer) null-safe. Make LockVisitor.applyWriteLocked(FailableConsumer) null-safe. + Make ObjectUtils.getFirstNonNull(Supplier...) null-safe. Bump commons-parent from 64 to 69 #1194. Bump org.codehaus.mojo:exec-maven-plugin from 3.1.1 to 3.2.0 #1175. diff --git a/src/main/java/org/apache/commons/lang3/ObjectUtils.java b/src/main/java/org/apache/commons/lang3/ObjectUtils.java index 083773943..138d67000 100644 --- a/src/main/java/org/apache/commons/lang3/ObjectUtils.java +++ b/src/main/java/org/apache/commons/lang3/ObjectUtils.java @@ -689,7 +689,7 @@ public class ObjectUtils { */ @SafeVarargs public static T getFirstNonNull(final Supplier... suppliers) { - return Streams.of(suppliers).map(s -> s != null ? s.get() : null).filter(Objects::nonNull).findFirst().orElse(null); + return Streams.of(suppliers).filter(Objects::nonNull).map(Supplier::get).filter(Objects::nonNull).findFirst().orElse(null); } /** diff --git a/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java b/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java index efa1f6c48..f950ad556 100644 --- a/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ObjectUtilsTest.java @@ -480,6 +480,7 @@ public class ObjectUtilsTest extends AbstractLangTest { @Test public void testGetFirstNonNull() { // first non-null + assertEquals("", ObjectUtils.getFirstNonNull(null, () -> "")); assertEquals("", ObjectUtils.getFirstNonNull(Suppliers.nul(), () -> "")); // first encountered value is used assertEquals("1", ObjectUtils.getFirstNonNull(Suppliers.nul(), () -> "1", () -> "2", Suppliers.nul()));