diff --git a/src/java.base/share/classes/java/nio/file/FileStore.java b/src/java.base/share/classes/java/nio/file/FileStore.java index 88c309b4370bf..18f6aa7982f25 100644 --- a/src/java.base/share/classes/java/nio/file/FileStore.java +++ b/src/java.base/share/classes/java/nio/file/FileStore.java @@ -27,6 +27,7 @@ import org.checkerframework.checker.interning.qual.UsesObjectEquals; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.checker.nullness.qual.Nullable; import java.nio.file.attribute.*; import java.io.IOException; @@ -46,7 +47,7 @@ * @since 1.7 */ -@AnnotatedFor({"interning"}) +@AnnotatedFor({"interning", "nullness"}) public abstract @UsesObjectEquals class FileStore { /** @@ -215,7 +216,7 @@ public long getBlockSize() throws IOException { * @return a file store attribute view of the specified type or * {@code null} if the attribute view is not available */ - public abstract V + public abstract V getFileStoreAttributeView(Class type); /** @@ -251,5 +252,5 @@ public long getBlockSize() throws IOException { * @throws IOException * if an I/O error occurs */ - public abstract Object getAttribute(String attribute) throws IOException; + public abstract @Nullable Object getAttribute(String attribute) throws IOException; } diff --git a/src/java.base/share/classes/java/nio/file/FileSystems.java b/src/java.base/share/classes/java/nio/file/FileSystems.java index 49c3710cc028d..a5c86d3ffb6df 100644 --- a/src/java.base/share/classes/java/nio/file/FileSystems.java +++ b/src/java.base/share/classes/java/nio/file/FileSystems.java @@ -27,6 +27,7 @@ import org.checkerframework.checker.interning.qual.UsesObjectEquals; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.checker.nullness.qual.Nullable; import java.nio.file.spi.FileSystemProvider; import java.net.URI; @@ -89,7 +90,7 @@ * @since 1.7 */ -@AnnotatedFor({"interning"}) +@AnnotatedFor({"interning", "nullness"}) public final @UsesObjectEquals class FileSystems { private FileSystems() { } @@ -331,7 +332,7 @@ public static FileSystem newFileSystem(URI uri, Map env) * if a security manager is installed and it denies an unspecified * permission required by the file system provider implementation */ - public static FileSystem newFileSystem(URI uri, Map env, ClassLoader loader) + public static FileSystem newFileSystem(URI uri, Map env, @Nullable ClassLoader loader) throws IOException { String scheme = uri.getScheme(); @@ -398,7 +399,7 @@ public static FileSystem newFileSystem(URI uri, Map env, ClassLoader l * permission */ public static FileSystem newFileSystem(Path path, - ClassLoader loader) + @Nullable ClassLoader loader) throws IOException { return newFileSystem(path, Map.of(), loader); @@ -521,7 +522,7 @@ public static FileSystem newFileSystem(Path path) throws IOException { * @since 13 */ public static FileSystem newFileSystem(Path path, Map env, - ClassLoader loader) + @Nullable ClassLoader loader) throws IOException { if (path == null) diff --git a/src/java.base/share/classes/java/nio/file/FileVisitor.java b/src/java.base/share/classes/java/nio/file/FileVisitor.java index 5c555ae77e19c..fe0816059efd1 100644 --- a/src/java.base/share/classes/java/nio/file/FileVisitor.java +++ b/src/java.base/share/classes/java/nio/file/FileVisitor.java @@ -28,6 +28,9 @@ import java.nio.file.attribute.BasicFileAttributes; import java.io.IOException; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.framework.qual.AnnotatedFor; + /** * A visitor of files. An implementation of this interface is provided to the * {@link Files#walkFileTree Files.walkFileTree} methods to visit each file in @@ -95,6 +98,7 @@ * @since 1.7 */ +@AnnotatedFor({"nullness"}) public interface FileVisitor { /** @@ -172,6 +176,6 @@ FileVisitResult visitFileFailed(T file, IOException exc) * @throws IOException * if an I/O error occurs */ - FileVisitResult postVisitDirectory(T dir, IOException exc) + FileVisitResult postVisitDirectory(T dir, @Nullable IOException exc) throws IOException; } diff --git a/src/java.base/share/classes/java/nio/file/Files.java b/src/java.base/share/classes/java/nio/file/Files.java index 2cb920d6d44d4..0a79e512a24e8 100644 --- a/src/java.base/share/classes/java/nio/file/Files.java +++ b/src/java.base/share/classes/java/nio/file/Files.java @@ -35,6 +35,7 @@ import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.dataflow.qual.SideEffectsOnly; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.checker.nullness.qual.Nullable; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -103,7 +104,7 @@ * @since 1.7 */ -@AnnotatedFor({"interning", "mustcall", "signedness"}) +@AnnotatedFor({"interning", "mustcall", "signedness", "nullness"}) public final @UsesObjectEquals class Files { // buffer size used for reading and writing private static final int BUFFER_SIZE = 8192; @@ -895,8 +896,8 @@ private static void createAndCheckIsDirectory(Path dir, */ @ReleasesNoLocks public static Path createTempFile(Path dir, - String prefix, - String suffix, + @Nullable String prefix, + @Nullable String suffix, FileAttribute... attrs) throws IOException { @@ -941,8 +942,8 @@ public static Path createTempFile(Path dir, * method is invoked to check write access to the file. */ @ReleasesNoLocks - public static Path createTempFile(String prefix, - String suffix, + public static Path createTempFile(@Nullable String prefix, + @Nullable String suffix, FileAttribute... attrs) throws IOException { @@ -996,7 +997,7 @@ public static Path createTempFile(String prefix, */ @ReleasesNoLocks public static Path createTempDirectory(Path dir, - String prefix, + @Nullable String prefix, FileAttribute... attrs) throws IOException { @@ -1038,7 +1039,7 @@ public static Path createTempDirectory(Path dir, * directory. */ @ReleasesNoLocks - public static Path createTempDirectory(String prefix, + public static Path createTempDirectory(@Nullable String prefix, FileAttribute... attrs) throws IOException { @@ -1763,7 +1764,7 @@ private static List loadInstalledDetectors() { * permission required by a file type detector implementation. */ @ReleasesNoLocks - public static String probeContentType(Path path) + public static @Nullable String probeContentType(Path path) throws IOException { // try installed file type detectors @@ -1822,7 +1823,7 @@ public static String probeContentType(Path path) * the attribute view type is not available */ @ReleasesNoLocks - public static V getFileAttributeView(Path path, + public static V getFileAttributeView(Path path, Class type, LinkOption... options) { diff --git a/src/java.base/share/classes/java/nio/file/LinkPermission.java b/src/java.base/share/classes/java/nio/file/LinkPermission.java index 81921f059cb90..f102eae2670aa 100644 --- a/src/java.base/share/classes/java/nio/file/LinkPermission.java +++ b/src/java.base/share/classes/java/nio/file/LinkPermission.java @@ -27,6 +27,9 @@ import java.security.BasicPermission; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.framework.qual.AnnotatedFor; + /** * The {@code Permission} class for link creation operations. * @@ -66,6 +69,8 @@ * @see Files#createLink * @see Files#createSymbolicLink */ + +@AnnotatedFor({"nullness"}) public final class LinkPermission extends BasicPermission { @java.io.Serial static final long serialVersionUID = -1441492453772213220L; @@ -102,7 +107,7 @@ public LinkPermission(String name) { * @throws IllegalArgumentException * if name is empty or invalid, or actions is a non-empty string */ - public LinkPermission(String name, String actions) { + public LinkPermission(String name, @Nullable String actions) { super(name); checkName(name); if (actions != null && !actions.isEmpty()) { diff --git a/src/java.base/share/classes/java/nio/file/SecureDirectoryStream.java b/src/java.base/share/classes/java/nio/file/SecureDirectoryStream.java index 8cfaea35f4a03..30d8ae65fa2a3 100644 --- a/src/java.base/share/classes/java/nio/file/SecureDirectoryStream.java +++ b/src/java.base/share/classes/java/nio/file/SecureDirectoryStream.java @@ -29,6 +29,9 @@ import java.util.Set; import java.io.IOException; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.checker.nullness.qual.AnnotatedFor; + /** * A {@code DirectoryStream} that defines operations on files that are located * relative to an open directory. A {@code SecureDirectoryStream} is intended @@ -56,6 +59,8 @@ * @since 1.7 */ +@AnnotatedFor({"nullness"}) + public interface SecureDirectoryStream extends DirectoryStream { @@ -271,7 +276,7 @@ void move(T srcpath, SecureDirectoryStream targetdir, T targetpath) * this directory stream, or {@code null} if the attribute view * type is not available */ - V getFileAttributeView(Class type); + @Nullable V getFileAttributeView(Class type); /** * Returns a new file attribute view to access the file attributes of a file @@ -306,7 +311,7 @@ void move(T srcpath, SecureDirectoryStream targetdir, T targetpath) * type is not available * */ - V getFileAttributeView(T path, + @Nullable V getFileAttributeView(T path, Class type, LinkOption... options); } diff --git a/src/java.base/share/classes/java/nio/file/SimpleFileVisitor.java b/src/java.base/share/classes/java/nio/file/SimpleFileVisitor.java index b4e9713c8e5c8..d9dacce1270bc 100644 --- a/src/java.base/share/classes/java/nio/file/SimpleFileVisitor.java +++ b/src/java.base/share/classes/java/nio/file/SimpleFileVisitor.java @@ -26,6 +26,7 @@ package java.nio.file; import org.checkerframework.checker.interning.qual.UsesObjectEquals; +import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.framework.qual.AnnotatedFor; import java.nio.file.attribute.BasicFileAttributes; @@ -43,7 +44,7 @@ * @since 1.7 */ -@AnnotatedFor({"interning"}) +@AnnotatedFor({"interning", "nullness"}) public @UsesObjectEquals class SimpleFileVisitor implements FileVisitor { /** * Initializes a new instance of this class. @@ -105,7 +106,7 @@ public FileVisitResult visitFileFailed(T file, IOException exc) * of the directory to terminate prematurely. */ @Override - public FileVisitResult postVisitDirectory(T dir, IOException exc) + public FileVisitResult postVisitDirectory(T dir, @Nullable IOException exc) throws IOException { Objects.requireNonNull(dir); diff --git a/src/java.base/share/classes/java/nio/file/WatchEvent.java b/src/java.base/share/classes/java/nio/file/WatchEvent.java index 25438a86f9a17..e71fc710d8816 100644 --- a/src/java.base/share/classes/java/nio/file/WatchEvent.java +++ b/src/java.base/share/classes/java/nio/file/WatchEvent.java @@ -25,6 +25,9 @@ package java.nio.file; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.framework.qual.AnnotatedFor; + /** * An event or a repeated event for an object that is registered with a {@link * WatchService}. @@ -44,7 +47,8 @@ * @since 1.7 */ -public interface WatchEvent { +@AnnotatedFor({"nullness"}) +public interface WatchEvent { /** * An event kind, for the purposes of identification. @@ -52,7 +56,7 @@ public interface WatchEvent { * @since 1.7 * @see StandardWatchEventKinds */ - public static interface Kind { + public static interface Kind { /** * Returns the name of the event kind. * diff --git a/src/java.base/share/classes/java/nio/file/WatchService.java b/src/java.base/share/classes/java/nio/file/WatchService.java index 042df2458f0da..2b5961571ee56 100644 --- a/src/java.base/share/classes/java/nio/file/WatchService.java +++ b/src/java.base/share/classes/java/nio/file/WatchService.java @@ -31,6 +31,7 @@ import org.checkerframework.checker.mustcall.qual.InheritableMustCall; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A watch service that watches registered objects for changes and @@ -105,7 +106,7 @@ * * @see FileSystem#newWatchService */ -@AnnotatedFor({"mustcall"}) +@AnnotatedFor({"mustcall", "nullness"}) @InheritableMustCall({}) public interface WatchService extends Closeable @@ -140,7 +141,7 @@ public interface WatchService * @throws ClosedWatchServiceException * if this watch service is closed */ - WatchKey poll(); + @Nullable WatchKey poll(); /** * Retrieves and removes the next watch key, waiting if necessary up to the @@ -160,7 +161,7 @@ public interface WatchService * @throws InterruptedException * if interrupted while waiting */ - WatchKey poll(long timeout, TimeUnit unit) + @Nullable WatchKey poll(long timeout, TimeUnit unit) throws InterruptedException; /** diff --git a/src/java.base/share/classes/java/nio/file/attribute/BasicFileAttributeView.java b/src/java.base/share/classes/java/nio/file/attribute/BasicFileAttributeView.java index 37508cfd2009e..0678814797a17 100644 --- a/src/java.base/share/classes/java/nio/file/attribute/BasicFileAttributeView.java +++ b/src/java.base/share/classes/java/nio/file/attribute/BasicFileAttributeView.java @@ -27,6 +27,9 @@ import java.io.IOException; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.framework.qual.AnnotatedFor; + /** * A file attribute view that provides a view of a basic set of file * attributes common to many file systems. The basic set of file attributes @@ -101,6 +104,7 @@ * @since 1.7 */ +@AnnotatedFor({"nullness"}) public interface BasicFileAttributeView extends FileAttributeView { @@ -176,7 +180,7 @@ public interface BasicFileAttributeView * * @see java.nio.file.Files#setLastModifiedTime */ - void setTimes(FileTime lastModifiedTime, - FileTime lastAccessTime, - FileTime createTime) throws IOException; + void setTimes(@Nullable FileTime lastModifiedTime, + @Nullable FileTime lastAccessTime, + @Nullable FileTime createTime) throws IOException; } diff --git a/src/java.base/share/classes/java/nio/file/attribute/BasicFileAttributes.java b/src/java.base/share/classes/java/nio/file/attribute/BasicFileAttributes.java index 2c20c09df883f..712fe7c31f4aa 100644 --- a/src/java.base/share/classes/java/nio/file/attribute/BasicFileAttributes.java +++ b/src/java.base/share/classes/java/nio/file/attribute/BasicFileAttributes.java @@ -27,6 +27,7 @@ import org.checkerframework.checker.index.qual.NonNegative; import org.checkerframework.framework.qual.AnnotatedFor; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Basic attributes associated with a file in a file system. @@ -46,7 +47,7 @@ * @see BasicFileAttributeView */ -@AnnotatedFor({"index"}) +@AnnotatedFor({"index", "nullness"}) public interface BasicFileAttributes { /** @@ -155,5 +156,5 @@ public interface BasicFileAttributes { * * @see java.nio.file.Files#walkFileTree */ - Object fileKey(); + @Nullable Object fileKey(); } diff --git a/src/java.base/share/classes/java/nio/file/spi/FileSystemProvider.java b/src/java.base/share/classes/java/nio/file/spi/FileSystemProvider.java index 5f1741f1f37cf..90ec81611ad2a 100644 --- a/src/java.base/share/classes/java/nio/file/spi/FileSystemProvider.java +++ b/src/java.base/share/classes/java/nio/file/spi/FileSystemProvider.java @@ -26,6 +26,7 @@ package java.nio.file.spi; import org.checkerframework.checker.interning.qual.UsesObjectEquals; +import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.framework.qual.AnnotatedFor; import java.nio.channels.AsynchronousFileChannel; @@ -113,7 +114,7 @@ * @since 1.7 */ -@AnnotatedFor({"interning"}) +@AnnotatedFor({"interning", "nullness"}) public abstract @UsesObjectEquals class FileSystemProvider { // lock using when loading providers private static final Object lock = new Object(); @@ -586,7 +587,7 @@ public FileChannel newFileChannel(Path path, */ public AsynchronousFileChannel newAsynchronousFileChannel(Path path, Set options, - ExecutorService executor, + @Nullable ExecutorService executor, FileAttribute... attrs) throws IOException { @@ -1074,7 +1075,7 @@ public abstract void checkAccess(Path path, AccessMode... modes) * @return a file attribute view of the specified type, or {@code null} if * the attribute view type is not available */ - public abstract V + public abstract V getFileAttributeView(Path path, Class type, LinkOption... options); /** diff --git a/src/java.base/share/classes/java/nio/file/spi/FileTypeDetector.java b/src/java.base/share/classes/java/nio/file/spi/FileTypeDetector.java index 5c64c267ec14b..29dac692d4913 100644 --- a/src/java.base/share/classes/java/nio/file/spi/FileTypeDetector.java +++ b/src/java.base/share/classes/java/nio/file/spi/FileTypeDetector.java @@ -25,6 +25,7 @@ package java.nio.file.spi; +import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.interning.qual.UsesObjectEquals; import org.checkerframework.framework.qual.AnnotatedFor; @@ -50,7 +51,7 @@ * @since 1.7 */ -@AnnotatedFor({"interning"}) +@AnnotatedFor({"interning", "nullable"}) public abstract @UsesObjectEquals class FileTypeDetector { private static Void checkPermission() { @@ -106,6 +107,6 @@ protected FileTypeDetector() { * * @see java.nio.file.Files#probeContentType */ - public abstract String probeContentType(Path path) + public abstract @Nullable String probeContentType(Path path) throws IOException; }