Skip to content

Commit a6dda25

Browse files
committed
AFSocketAddress: Prevent false-positive "mutable object" warnings
When passing AFSocketAddress as constructor arguments, spotbugs may erroneously claim that we expose class internals due to the address being mutable. In fact, all mutable fields of AFSocketAddress are only mutable so we can support deserialization, and are not modifiable otherwise. Add @immutable, and suppress some corresponding warnings in code.
1 parent ca81fd4 commit a6dda25

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

junixsocket-common/src/main/java/org/newsclub/net/unix/AFSocketAddress.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@
4242
import org.eclipse.jdt.annotation.NonNull;
4343
import org.eclipse.jdt.annotation.Nullable;
4444

45+
import com.google.errorprone.annotations.Immutable;
46+
import com.kohlschutter.annotations.compiletime.SuppressFBWarnings;
47+
4548
/**
4649
* Some {@link SocketAddress} that is supported by junixsocket, such as {@link AFUNIXSocketAddress}.
4750
*
4851
* @author Christian Kohlschütter
4952
*/
53+
@Immutable
5054
@SuppressWarnings({"PMD.CouplingBetweenObjects", "PMD.CyclomaticComplexity"})
5155
public abstract class AFSocketAddress extends InetSocketAddress {
5256
private static final long serialVersionUID = 1L; // do not change!
@@ -91,12 +95,15 @@ protected ByteBuffer initialValue() {
9195
* Some byte-level representation of this address, which can only be converted to a native
9296
* representation in combination with the domain ID.
9397
*/
98+
@SuppressFBWarnings("JCIP_FIELD_ISNT_FINAL_IN_IMMUTABLE_CLASS")
9499
private byte[] bytes;
95100

96101
/**
97102
* An {@link InetAddress}-wrapped representation of this address. Only created upon demand.
98103
*/
99-
private InetAddress inetAddress = null;
104+
@SuppressFBWarnings("JCIP_FIELD_ISNT_FINAL_IN_IMMUTABLE_CLASS") // only modified during
105+
// construction/deserialization
106+
private InetAddress inetAddress = null; // derived from bytes
100107

101108
/**
102109
* The system-native representation of this address, or {@code null}.

0 commit comments

Comments
 (0)