From 9006e7087bcefaecaf4c80489cb8c9e7a796d583 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 1 Mar 2022 13:43:50 +0100 Subject: Ensure nullness correctness using Checker Framework. Change-Id: Ie5a7749194313664a206e44597091a62afca9bdb --- .../java/eu/mulk/jgvariant/ostree/ByteString.java | 3 ++- .../eu/mulk/jgvariant/ostree/DeltaSuperblock.java | 28 +++++++++++----------- 2 files changed, 16 insertions(+), 15 deletions(-) (limited to 'jgvariant-ostree/src/main/java') diff --git a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/ByteString.java b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/ByteString.java index 3a8185c..cfe3635 100644 --- a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/ByteString.java +++ b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/ByteString.java @@ -10,6 +10,7 @@ import java.util.Base64; import java.util.HexFormat; import java.util.stream.IntStream; import java.util.stream.Stream; +import org.jetbrains.annotations.Nullable; /** * A wrapper for a {@code byte[]} that implements {@link #equals(Object)}, {@link #hashCode()}, and @@ -31,7 +32,7 @@ public record ByteString(byte[] bytes) { } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { return (o instanceof ByteString byteString) && Arrays.equals(bytes, byteString.bytes); } diff --git a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaSuperblock.java b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaSuperblock.java index 52b970f..50da203 100644 --- a/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaSuperblock.java +++ b/jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaSuperblock.java @@ -70,20 +70,20 @@ public record DeltaSuperblock( Decoder.ofByteArray().map(DeltaSuperblock::parseDeltaNameList), Decoder.ofArray(DeltaMetaEntry.decoder()).withByteOrder(ByteOrder.LITTLE_ENDIAN), Decoder.ofArray(DeltaFallback.decoder()).withByteOrder(ByteOrder.LITTLE_ENDIAN)) - .map( - deltaSuperblock -> { - // Fix up the endianness of the 'entries' and 'fallbacks' fields, which have - // unspecified byte order. - var endiannessMetadatum = - deltaSuperblock.metadata().fields().get("ostree.endianness"); - if (endiannessMetadatum != null - && endiannessMetadatum.value() instanceof Byte endiannessByte - && endiannessByte == (byte) 'B') { - return deltaSuperblock.byteSwapped(); - } else { - return deltaSuperblock; - } - }); + .map(DeltaSuperblock::byteSwappedIfBigEndian); + + private DeltaSuperblock byteSwappedIfBigEndian() { + // Fix up the endianness of the 'entries' and 'fallbacks' fields, which have + // unspecified byte order. + var endiannessMetadatum = metadata().fields().get("ostree.endianness"); + if (endiannessMetadatum != null + && endiannessMetadatum.value() instanceof Byte endiannessByte + && endiannessByte == (byte) 'B') { + return byteSwapped(); + } else { + return this; + } + } private DeltaSuperblock byteSwapped() { return new DeltaSuperblock( -- cgit v1.2.3