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

commit 19bac38cbaaa3fd7560b59e12bc8a5dfec9519a5
Author: Gary D. Gregory <[email protected]>
AuthorDate: Tue Sep 9 16:30:31 2025 -0700

    Add FailableByteSupplier
---
 src/changes/changes.xml                            |  1 +
 .../lang3/function/FailableByteSupplier.java       | 38 ++++++++++++++++++++++
 .../lang3/function/FailableFunctionsTest.java      | 30 +++++++++++++++++
 3 files changed, 69 insertions(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d15bc90c6..fb8fa75a7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -86,6 +86,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add org.apache.commons.lang3.time.DateUtils.toZonedDateTime(Date[, 
TimeZone]).</action>
     <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add ByteConsumer.</action>
     <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add FailableByteConsumer.</action>
+    <action                   type="add" dev="ggregory" due-to="Gary 
Gregory">Add FailableByteSupplier.</action>
     <!-- UPDATE -->
     <action type="update" dev="ggregory" due-to="Gary Gregory">[test] Bump 
org.apache.commons:commons-text from 1.13.1 to 1.14.0.</action>
     <action type="update" dev="ggregory" due-to="Gary Gregory">Bump 
org.apache.commons:commons-parent from 85 to 87.</action>
diff --git 
a/src/main/java/org/apache/commons/lang3/function/FailableByteSupplier.java 
b/src/main/java/org/apache/commons/lang3/function/FailableByteSupplier.java
new file mode 100644
index 000000000..507548cc5
--- /dev/null
+++ b/src/main/java/org/apache/commons/lang3/function/FailableByteSupplier.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.function;
+
+import java.util.function.IntSupplier;
+
+/**
+ * A functional interface like {@link IntSupplier}, but for a byte, that 
declares a {@link Throwable}.
+ *
+ * @param <E> The kind of thrown exception or error.
+ * @since 3.19
+ */
+@FunctionalInterface
+public interface FailableByteSupplier<E extends Throwable> {
+
+    /**
+     * Supplies a byte.
+     *
+     * @return a result
+     * @throws E if the supplier fails
+     */
+    byte getAsByte() throws E;
+}
diff --git 
a/src/test/java/org/apache/commons/lang3/function/FailableFunctionsTest.java 
b/src/test/java/org/apache/commons/lang3/function/FailableFunctionsTest.java
index bee264458..f86886d2a 100644
--- a/src/test/java/org/apache/commons/lang3/function/FailableFunctionsTest.java
+++ b/src/test/java/org/apache/commons/lang3/function/FailableFunctionsTest.java
@@ -1678,6 +1678,36 @@ public void accept(final byte value) throws Throwable {
         }.accept((byte) 0));
     }
 
+    /**
+     * Tests that our failable interface is properly defined to throw any 
exception using String and IOExceptions as
+     * generic test types.
+     */
+    @Test
+    void testThrows_FailableByteSupplier_IOException() {
+        assertThrows(IOException.class, () -> new 
FailableByteSupplier<IOException>() {
+
+            @Override
+            public byte getAsByte() throws IOException {
+                throw new IOException("test");
+            }
+        }.getAsByte());
+    }
+
+    /**
+     * Tests that our failable interface is properly defined to throw any 
exception using the top level generic types
+     * Object and Throwable.
+     */
+    @Test
+    void testThrows_FailableByteSupplier_Throwable() {
+        assertThrows(IOException.class, () -> new 
FailableByteSupplier<Throwable>() {
+
+            @Override
+            public byte getAsByte() throws Throwable {
+                throw new IOException("test");
+            }
+        }.getAsByte());
+    }
+
     /**
      * Tests that our failable interface is properly defined to throw any 
exception using the top level generic types
      * Object and Throwable.

Reply via email to