Skip to content

Commit

Permalink
Fix Spotbugs SE_TRANSIENT_FIELD_NOT_RESTORED issues
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
garydgregory committed Jan 9, 2025
1 parent 744a8c3 commit bdcc5a0
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/main/java/org/apache/commons/lang3/builder/DiffBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ public Builder<T> setToStringFormat(final String toStringFormat) {
}
}

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);
Expand All @@ -188,6 +188,15 @@ public T getRight() {

}

/**
* 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";

/**
Expand Down Expand Up @@ -264,7 +273,7 @@ private DiffBuilder(final T left, final T right, final ToStringStyle style, fina
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;
}
Expand Down

0 comments on commit bdcc5a0

Please sign in to comment.