From 91dbd7474041880d2babc7124fcce20fe61493c1 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Mon, 17 Oct 2022 19:38:56 +0200 Subject: Remove Checker Framework; add NullAway, Picnic Error Prone Support. Change-Id: I6558f0b4db0f9a192c18bbe45e2eaf10595bc666 --- .../src/main/java/eu/mulk/jgvariant/core/Decoder.java | 16 +++++++++++----- .../src/main/java/eu/mulk/jgvariant/core/Signature.java | 10 ++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'jgvariant-core/src/main') diff --git a/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java b/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java index 2cb36c6..4538900 100644 --- a/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java +++ b/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java @@ -5,15 +5,16 @@ package eu.mulk.jgvariant.core; import static java.nio.ByteOrder.LITTLE_ENDIAN; +import static java.util.Objects.requireNonNullElse; import static java.util.stream.Collectors.toMap; +import com.google.errorprone.annotations.Immutable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.RecordComponent; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.charset.Charset; import java.text.ParseException; -import java.util.AbstractMap.SimpleImmutableEntry; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -56,8 +57,9 @@ import org.jetbrains.annotations.Nullable; * * @param the type that the {@link Decoder} can decode. */ -@SuppressWarnings("java:S1610") @API(status = Status.EXPERIMENTAL) +@Immutable +@SuppressWarnings({"ImmutableListOf", "InvalidInlineTag", "java:S1610", "UnescapedEntity"}) public abstract class Decoder { private Decoder() {} @@ -523,6 +525,7 @@ public abstract class Decoder { } } + @SuppressWarnings("Immutable") private static class TupleDecoder extends Decoder { private final Decoder[] componentDecoders; @@ -625,7 +628,7 @@ public abstract class Decoder { @SuppressWarnings("unchecked") public Map.@NotNull Entry decode(ByteBuffer byteSlice) { Object[] components = tupleDecoder.decode(byteSlice); - return new SimpleImmutableEntry<>((K) components[0], (V) components[1]); + return Map.entry((K) components[0], (V) components[1]); } } @@ -800,6 +803,7 @@ public abstract class Decoder { } } + @SuppressWarnings("Immutable") private class MappingDecoder extends Decoder { private final Function<@NotNull T, @NotNull U> function; @@ -824,6 +828,7 @@ public abstract class Decoder { } } + @SuppressWarnings("Immutable") private class ContramappingDecoder extends Decoder { private final UnaryOperator function; @@ -879,6 +884,7 @@ public abstract class Decoder { return byteSlice.slice(index, length).order(byteSlice.order()); } + @SuppressWarnings("Immutable") private static class PredicateDecoder extends Decoder { private final Predicate selector; @@ -900,8 +906,8 @@ public abstract class Decoder { throw new IllegalArgumentException( "incompatible sizes in predicate branches: then=%s, else=%s" .formatted( - Objects.requireNonNullElse(thenDecoder.fixedSize(), "(null)"), - Objects.requireNonNullElse(elseDecoder.fixedSize(), "(null)"))); + requireNonNullElse(thenDecoder.fixedSize(), "(null)"), + requireNonNullElse(elseDecoder.fixedSize(), "(null)"))); } } diff --git a/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Signature.java b/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Signature.java index cc9674d..4c8cd65 100644 --- a/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Signature.java +++ b/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Signature.java @@ -4,8 +4,10 @@ package eu.mulk.jgvariant.core; +import static java.nio.charset.StandardCharsets.US_ASCII; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.util.ArrayList; import java.util.List; @@ -41,7 +43,7 @@ public final class Signature { this.decoder = parseSignature(signatureBytes); signatureBytes.rewind(); - this.signatureString = StandardCharsets.US_ASCII.decode(signatureBytes).toString(); + this.signatureString = US_ASCII.decode(signatureBytes).toString(); } static Signature parse(ByteBuffer signatureBytes) throws ParseException { @@ -49,7 +51,7 @@ public final class Signature { } public static Signature parse(String signatureString) throws ParseException { - var signatureBytes = ByteBuffer.wrap(signatureString.getBytes(StandardCharsets.US_ASCII)); + var signatureBytes = ByteBuffer.wrap(signatureString.getBytes(US_ASCII)); return parse(signatureBytes); } @@ -93,7 +95,7 @@ public final class Signature { case 'i', 'u' -> Decoder.ofInt(); case 'x', 't' -> Decoder.ofLong(); case 'd' -> Decoder.ofDouble(); - case 's', 'o', 'g' -> Decoder.ofString(StandardCharsets.UTF_8); + case 's', 'o', 'g' -> Decoder.ofString(UTF_8); case 'v' -> Decoder.ofVariant(); case 'm' -> Decoder.ofMaybe(parseSignature(signature)); case '(' -> Decoder.ofStructure(parseTupleTypes(signature).toArray(new Decoder[0])); -- cgit v1.2.3