aboutsummaryrefslogtreecommitdiff
path: root/jgvariant-ostree
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2022-03-01 13:43:50 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2022-03-01 13:43:50 +0100
commit9006e7087bcefaecaf4c80489cb8c9e7a796d583 (patch)
tree8edf503f5b0d54c18c8c2ec24abb2769dc8685a2 /jgvariant-ostree
parent0ad6a55f3faa0ff8c42321edc6b27bbcc358b709 (diff)
Ensure nullness correctness using Checker Framework.
Change-Id: Ie5a7749194313664a206e44597091a62afca9bdb
Diffstat (limited to 'jgvariant-ostree')
-rw-r--r--jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/ByteString.java3
-rw-r--r--jgvariant-ostree/src/main/java/eu/mulk/jgvariant/ostree/DeltaSuperblock.java28
-rw-r--r--jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderTest.java1
3 files changed, 17 insertions, 15 deletions
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(
diff --git a/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderTest.java b/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderTest.java
index 5c1dd79..d8ad271 100644
--- a/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderTest.java
+++ b/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderTest.java
@@ -17,6 +17,7 @@ import java.util.Map;
import org.junit.jupiter.api.Test;
@TestWithResources
+@SuppressWarnings("initialization.field.uninitialized")
class OstreeDecoderTest {
@GivenBinaryResource("/ostree/summary")