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 bdcc5a050 Fix Spotbugs SE_TRANSIENT_FIELD_NOT_RESTORED issues
bdcc5a050 is described below

commit bdcc5a050201d9bba2f723e1fcf45fe42d84451e
Author: Gary Gregory <[email protected]>
AuthorDate: Thu Jan 9 15:29:10 2025 -0500

    Fix Spotbugs SE_TRANSIENT_FIELD_NOT_RESTORED issues
    
    [ERROR] Medium: The field
    org.apache.commons.lang3.builder.DiffBuilder$SDiff.leftSupplier is
    transient but isn't set by deserialization
    [org.apache.commons.lang3.builder.DiffBuilder$SDiff] In DiffBuilder.java
    SE_TRANSIENT_FIELD_NOT_RESTORED
    [ERROR] Medium: The field
    org.apache.commons.lang3.builder.DiffBuilder$SDiff.rightSupplier is
    transient but isn't set by deserialization
    [org.apache.commons.lang3.builder.DiffBuilder$SDiff] In DiffBuilder.java
    SE_TRANSIENT_FIELD_NOT_RESTORED
---
 .../org/apache/commons/lang3/builder/DiffBuilder.java | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java 
b/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java
index ab358e266..cd4b433ab 100644
--- a/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java
@@ -164,13 +164,13 @@ public class DiffBuilder<T> implements 
Builder<DiffResult<T>> {
         }
     }
 
-    private static final class SDiff<T, S extends Supplier<T> & Serializable> 
extends Diff<T> {
+    private static final class SDiff<T> extends Diff<T> {
 
         private static final long serialVersionUID = 1L;
-        private final transient S leftSupplier;
-        private final transient S rightSupplier;
+        private final SerializableSupplier<T> leftSupplier;
+        private final SerializableSupplier<T> rightSupplier;
 
-        private SDiff(final String fieldName, final S leftSupplier, final S 
rightSupplier, final Class<T> type) {
+        private SDiff(final String fieldName, final SerializableSupplier<T> 
leftSupplier, final SerializableSupplier<T> rightSupplier, final Class<T> type) 
{
             super(fieldName, type);
             this.leftSupplier = Objects.requireNonNull(leftSupplier);
             this.rightSupplier = Objects.requireNonNull(rightSupplier);
@@ -188,6 +188,15 @@ public class DiffBuilder<T> implements 
Builder<DiffResult<T>> {
 
     }
 
+    /**
+     * Private interface while we still have to support serialization.
+     *
+     * @param <T> the type of results supplied by this supplier.
+     */
+    private interface SerializableSupplier<T> extends Supplier<T>, 
Serializable {
+        // empty
+    }
+
     static final String TO_STRING_FORMAT = "%s differs from %s";
 
     /**
@@ -264,7 +273,7 @@ public class DiffBuilder<T> implements 
Builder<DiffResult<T>> {
         this.equals = testObjectsEquals && Objects.equals(left, right);
     }
 
-    private <F, S extends Supplier<F> & Serializable> DiffBuilder<T> add(final 
String fieldName, final S left, final S right, final Class<F> type) {
+    private <F> DiffBuilder<T> add(final String fieldName, final 
SerializableSupplier<F> left, final SerializableSupplier<F> right, final 
Class<F> type) {
         diffs.add(new SDiff<>(fieldName, left, right, type));
         return this;
     }

Reply via email to