From 6ee196553d82d2d370823cddece93ee539a754e6 Mon Sep 17 00:00:00 2001 From: Chris Povirk Date: Mon, 11 Nov 2024 11:10:09 -0500 Subject: [PATCH] Annotate much of `java.util.zip`. Prompted by https://github.com/google/xplat/commit/4461165b65150c7f7b9992d284644f896a2d7a0f. --- .../share/classes/java/util/zip/Adler32.java | 2 ++ .../share/classes/java/util/zip/Checksum.java | 5 +++-- .../classes/java/util/zip/DataFormatException.java | 6 +++++- .../share/classes/java/util/zip/Deflater.java | 3 ++- .../classes/java/util/zip/DeflaterOutputStream.java | 2 ++ .../share/classes/java/util/zip/Inflater.java | 3 ++- .../classes/java/util/zip/InflaterOutputStream.java | 13 ++++--------- .../share/classes/java/util/zip/ZipException.java | 6 ++++-- 8 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/java.base/share/classes/java/util/zip/Adler32.java b/src/java.base/share/classes/java/util/zip/Adler32.java index 807c08ced8a..0174e41d7d2 100644 --- a/src/java.base/share/classes/java/util/zip/Adler32.java +++ b/src/java.base/share/classes/java/util/zip/Adler32.java @@ -30,6 +30,7 @@ import jdk.internal.util.Preconditions; import jdk.internal.vm.annotation.IntrinsicCandidate; import sun.nio.ch.DirectBuffer; +import org.jspecify.annotations.NullMarked; import static java.util.zip.ZipUtils.NIO_ACCESS; @@ -44,6 +45,7 @@ * @author David Connelly * @since 1.1 */ +@NullMarked public class Adler32 implements Checksum { private int adler = 1; diff --git a/src/java.base/share/classes/java/util/zip/Checksum.java b/src/java.base/share/classes/java/util/zip/Checksum.java index a0c6793cae2..6f8568b4df6 100644 --- a/src/java.base/share/classes/java/util/zip/Checksum.java +++ b/src/java.base/share/classes/java/util/zip/Checksum.java @@ -28,6 +28,7 @@ import org.checkerframework.framework.qual.AnnotatedFor; import java.nio.ByteBuffer; +import org.jspecify.annotations.NullMarked; /** * An interface representing a data checksum. @@ -35,7 +36,7 @@ * @author David Connelly * @since 1.1 */ -@AnnotatedFor({"index"}) +@NullMarked public interface Checksum { /** @@ -69,7 +70,7 @@ default public void update(byte[] b) { * @param off the start offset of the data * @param len the number of bytes to use for the update */ - public void update(byte[] b, @IndexOrHigh({"#1"}) int off, @IndexOrHigh({"#1"}) int len); + public void update(byte[] b, int off, int len); /** * Updates the current checksum with the bytes from the specified buffer. diff --git a/src/java.base/share/classes/java/util/zip/DataFormatException.java b/src/java.base/share/classes/java/util/zip/DataFormatException.java index cfb6eb6d6e7..f726cf68364 100644 --- a/src/java.base/share/classes/java/util/zip/DataFormatException.java +++ b/src/java.base/share/classes/java/util/zip/DataFormatException.java @@ -25,12 +25,16 @@ package java.util.zip; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + /** * Signals that a data format error has occurred. * * @author David Connelly * @since 1.1 */ +@NullMarked public class DataFormatException extends Exception { @java.io.Serial private static final long serialVersionUID = 2219632870893641452L; @@ -47,7 +51,7 @@ public DataFormatException() { * A detail message is a String that describes this particular exception. * @param s the String containing a detail message */ - public DataFormatException(String s) { + public DataFormatException(@Nullable String s) { super(s); } } diff --git a/src/java.base/share/classes/java/util/zip/Deflater.java b/src/java.base/share/classes/java/util/zip/Deflater.java index a23f8395c21..0bd946f2c75 100644 --- a/src/java.base/share/classes/java/util/zip/Deflater.java +++ b/src/java.base/share/classes/java/util/zip/Deflater.java @@ -33,6 +33,7 @@ import jdk.internal.ref.CleanerFactory; import jdk.internal.util.Preconditions; import sun.nio.ch.DirectBuffer; +import org.jspecify.annotations.NullMarked; import static java.util.zip.ZipUtils.NIO_ACCESS; @@ -70,7 +71,7 @@ * @author David Connelly * @since 1.1 */ - +@NullMarked public class Deflater { private final DeflaterZStreamRef zsRef; diff --git a/src/java.base/share/classes/java/util/zip/DeflaterOutputStream.java b/src/java.base/share/classes/java/util/zip/DeflaterOutputStream.java index 66630d5adf0..9b0ae118de4 100644 --- a/src/java.base/share/classes/java/util/zip/DeflaterOutputStream.java +++ b/src/java.base/share/classes/java/util/zip/DeflaterOutputStream.java @@ -29,6 +29,7 @@ import java.io.OutputStream; import java.io.InputStream; import java.io.IOException; +import org.jspecify.annotations.NullMarked; /** * This class implements an output stream filter for compressing data in @@ -42,6 +43,7 @@ * @author David Connelly * @since 1.1 */ +@NullMarked public class DeflaterOutputStream extends FilterOutputStream { /** * Compressor for this stream. diff --git a/src/java.base/share/classes/java/util/zip/Inflater.java b/src/java.base/share/classes/java/util/zip/Inflater.java index 109208bd9ad..37994944762 100644 --- a/src/java.base/share/classes/java/util/zip/Inflater.java +++ b/src/java.base/share/classes/java/util/zip/Inflater.java @@ -33,6 +33,7 @@ import jdk.internal.ref.CleanerFactory; import jdk.internal.util.Preconditions; import sun.nio.ch.DirectBuffer; +import org.jspecify.annotations.NullMarked; import static java.util.zip.ZipUtils.NIO_ACCESS; @@ -70,7 +71,7 @@ * @since 1.1 * */ - +@NullMarked public class Inflater { private final InflaterZStreamRef zsRef; diff --git a/src/java.base/share/classes/java/util/zip/InflaterOutputStream.java b/src/java.base/share/classes/java/util/zip/InflaterOutputStream.java index 213c4801cf5..9b1ac3e453e 100644 --- a/src/java.base/share/classes/java/util/zip/InflaterOutputStream.java +++ b/src/java.base/share/classes/java/util/zip/InflaterOutputStream.java @@ -25,15 +25,11 @@ package java.util.zip; -import org.checkerframework.checker.index.qual.IndexOrHigh; -import org.checkerframework.checker.index.qual.Positive; -import org.checkerframework.checker.signedness.qual.PolySigned; -import org.checkerframework.framework.qual.AnnotatedFor; - import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Objects; +import org.jspecify.annotations.NullMarked; /** * Implements an output stream filter for uncompressing data stored in the @@ -46,8 +42,7 @@ * @see DeflaterInputStream * @see DeflaterOutputStream */ - -@AnnotatedFor({"index", "signedness"}) +@NullMarked public class InflaterOutputStream extends FilterOutputStream { /** Decompressor for this stream. */ protected final Inflater inf; @@ -107,7 +102,7 @@ public InflaterOutputStream(OutputStream out, Inflater infl) { * @throws IllegalArgumentException if {@code bufLen <= 0} * @throws NullPointerException if {@code out} or {@code infl} is null */ - public InflaterOutputStream(OutputStream out, Inflater infl, @Positive int bufLen) { + public InflaterOutputStream(OutputStream out, Inflater infl, int bufLen) { super(out); // Sanity checks @@ -225,7 +220,7 @@ public void write(int b) throws IOException { * @throws NullPointerException if {@code b} is null * @throws ZipException if a compression (ZIP) format error occurs */ - public void write(@PolySigned byte[] b, @IndexOrHigh({"#1"}) int off, @IndexOrHigh({"#1"}) int len) throws IOException { + public void write(byte[] b, int off, int len) throws IOException { // Sanity checks ensureOpen(); if (b == null) { diff --git a/src/java.base/share/classes/java/util/zip/ZipException.java b/src/java.base/share/classes/java/util/zip/ZipException.java index 8c4f96ccbb7..66e530d7f73 100644 --- a/src/java.base/share/classes/java/util/zip/ZipException.java +++ b/src/java.base/share/classes/java/util/zip/ZipException.java @@ -26,6 +26,8 @@ package java.util.zip; import java.io.IOException; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; /** * Signals that a ZIP exception of some sort has occurred. @@ -33,7 +35,7 @@ * @see java.io.IOException * @since 1.1 */ - +@NullMarked public class ZipException extends IOException { @java.io.Serial private static final long serialVersionUID = 8000196834066748623L; @@ -53,7 +55,7 @@ public ZipException() { * @param s the detail message. */ - public ZipException(String s) { + public ZipException(@Nullable String s) { super(s); } }