diff --git a/jimfs/pom.xml b/jimfs/pom.xml index d6a4d9d9..85bd1731 100644 --- a/jimfs/pom.xml +++ b/jimfs/pom.xml @@ -60,6 +60,11 @@ jsr305 true + + org.checkerframework + checker-compat-qual + true + diff --git a/jimfs/src/main/java/com/google/common/jimfs/AbstractWatchService.java b/jimfs/src/main/java/com/google/common/jimfs/AbstractWatchService.java index 46822da0..6b4326d0 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/AbstractWatchService.java +++ b/jimfs/src/main/java/com/google/common/jimfs/AbstractWatchService.java @@ -41,7 +41,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Abstract implementation of {@link WatchService}. Provides the means for registering and managing @@ -90,14 +90,14 @@ ImmutableList queuedKeys() { return ImmutableList.copyOf(queue); } - @Nullable + @NullableDecl @Override public WatchKey poll() { checkOpen(); return check(queue.poll()); } - @Nullable + @NullableDecl @Override public WatchKey poll(long timeout, TimeUnit unit) throws InterruptedException { checkOpen(); @@ -111,8 +111,8 @@ public WatchKey take() throws InterruptedException { } /** Returns the given key, throwing an exception if it's the poison. */ - @Nullable - private WatchKey check(@Nullable WatchKey key) { + @NullableDecl + private WatchKey check(@NullableDecl WatchKey key) { if (key == poison) { // ensure other blocking threads get the poison queue.offer(poison); @@ -142,9 +142,9 @@ static final class Event implements WatchEvent { private final Kind kind; private final int count; - @Nullable private final T context; + @NullableDecl private final T context; - public Event(Kind kind, int count, @Nullable T context) { + public Event(Kind kind, int count, @NullableDecl T context) { this.kind = checkNotNull(kind); checkArgument(count >= 0, "count (%s) must be non-negative", count); this.count = count; @@ -161,7 +161,7 @@ public int count() { return count; } - @Nullable + @NullableDecl @Override public T context() { return context; @@ -214,7 +214,7 @@ private static WatchEvent overflowEvent(int count) { public Key( AbstractWatchService watcher, - @Nullable Watchable watchable, + @NullableDecl Watchable watchable, Iterable> subscribedTypes) { this.watcher = checkNotNull(watcher); this.watchable = watchable; // nullable for Watcher poison diff --git a/jimfs/src/main/java/com/google/common/jimfs/AclAttributeProvider.java b/jimfs/src/main/java/com/google/common/jimfs/AclAttributeProvider.java index 7a36a6db..1fa0f155 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/AclAttributeProvider.java +++ b/jimfs/src/main/java/com/google/common/jimfs/AclAttributeProvider.java @@ -29,7 +29,7 @@ import java.nio.file.attribute.UserPrincipal; import java.util.List; import java.util.Map; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Attribute provider that provides the {@link AclFileAttributeView} ("acl"). @@ -71,7 +71,7 @@ public ImmutableSet fixedAttributes() { return ImmutableMap.of("acl:acl", acl); } - @Nullable + @NullableDecl @Override public Object get(File file, String attribute) { if (attribute.equals("acl")) { diff --git a/jimfs/src/main/java/com/google/common/jimfs/AttributeProvider.java b/jimfs/src/main/java/com/google/common/jimfs/AttributeProvider.java index 249602b7..f5cade23 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/AttributeProvider.java +++ b/jimfs/src/main/java/com/google/common/jimfs/AttributeProvider.java @@ -24,7 +24,7 @@ import java.nio.file.attribute.FileAttributeView; import java.util.Arrays; import java.util.Map; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Abstract provider for handling a specific file attribute view. @@ -87,7 +87,7 @@ public ImmutableSet attributes(File file) { * Returns the value of the given attribute in the given file or null if the attribute is not * supported by this provider. */ - @Nullable + @NullableDecl public abstract Object get(File file, String attribute); /** @@ -108,7 +108,7 @@ public ImmutableSet attributes(File file) { * Returns the type of file attributes object this provider supports, or null if it doesn't * support reading its attributes as an object. */ - @Nullable + @NullableDecl public Class attributesType() { return null; } diff --git a/jimfs/src/main/java/com/google/common/jimfs/AttributeService.java b/jimfs/src/main/java/com/google/common/jimfs/AttributeService.java index 5081ede4..f3670fb2 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/AttributeService.java +++ b/jimfs/src/main/java/com/google/common/jimfs/AttributeService.java @@ -36,7 +36,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Service providing all attribute related operations for a file store. One piece of the file store @@ -204,7 +204,7 @@ public Object getAttribute(File file, String view, String attribute) { return value; } - @Nullable + @NullableDecl private Object getAttributeInternal(File file, String view, String attribute) { AttributeProvider provider = providersByName.get(view); if (provider == null) { @@ -259,7 +259,7 @@ private void setAttributeInternal( * if the view type is not supported. */ @SuppressWarnings("unchecked") - @Nullable + @NullableDecl public V getFileAttributeView(FileLookup lookup, Class type) { AttributeProvider provider = providersByViewType.get(type); diff --git a/jimfs/src/main/java/com/google/common/jimfs/BasicAttributeProvider.java b/jimfs/src/main/java/com/google/common/jimfs/BasicAttributeProvider.java index 0d62fdb9..6315ab70 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/BasicAttributeProvider.java +++ b/jimfs/src/main/java/com/google/common/jimfs/BasicAttributeProvider.java @@ -23,7 +23,7 @@ import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.FileAttributeView; import java.nio.file.attribute.FileTime; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Attribute provider that provides attributes common to all file systems, the {@link @@ -148,9 +148,9 @@ public BasicFileAttributes readAttributes() throws IOException { @Override public void setTimes( - @Nullable FileTime lastModifiedTime, - @Nullable FileTime lastAccessTime, - @Nullable FileTime createTime) + @NullableDecl FileTime lastModifiedTime, + @NullableDecl FileTime lastAccessTime, + @NullableDecl FileTime createTime) throws IOException { File file = lookupFile(); diff --git a/jimfs/src/main/java/com/google/common/jimfs/Configuration.java b/jimfs/src/main/java/com/google/common/jimfs/Configuration.java index b7ef0472..06630eb7 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/Configuration.java +++ b/jimfs/src/main/java/com/google/common/jimfs/Configuration.java @@ -44,7 +44,7 @@ import java.util.Map; import java.util.Set; import java.util.regex.Pattern; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Immutable configuration for an in-memory file system. A {@code Configuration} is passed to a @@ -434,7 +434,7 @@ private ImmutableSet checkNormalizations( } private static void checkNormalizationNotSet( - PathNormalization n, @Nullable PathNormalization set) { + PathNormalization n, @NullableDecl PathNormalization set) { if (set != null) { throw new IllegalArgumentException( "can't set normalization " + n + ": normalization " + set + " already set"); diff --git a/jimfs/src/main/java/com/google/common/jimfs/Directory.java b/jimfs/src/main/java/com/google/common/jimfs/Directory.java index 57448591..d1a1ebea 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/Directory.java +++ b/jimfs/src/main/java/com/google/common/jimfs/Directory.java @@ -20,7 +20,7 @@ import com.google.common.collect.AbstractIterator; import com.google.common.collect.ImmutableSortedSet; import java.util.Iterator; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * A table of {@linkplain DirectoryEntry directory entries}. @@ -103,7 +103,7 @@ public boolean isEmpty() { } /** Returns the entry for the given name in this table or null if no such entry exists. */ - @Nullable + @NullableDecl public DirectoryEntry get(Name name) { int index = bucketIndex(name, table.length); @@ -334,7 +334,7 @@ DirectoryEntry remove(Name name) { public Iterator iterator() { return new AbstractIterator() { int index; - @Nullable DirectoryEntry entry; + @NullableDecl DirectoryEntry entry; @Override protected DirectoryEntry computeNext() { diff --git a/jimfs/src/main/java/com/google/common/jimfs/DirectoryEntry.java b/jimfs/src/main/java/com/google/common/jimfs/DirectoryEntry.java index ad609e81..5bff50f5 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/DirectoryEntry.java +++ b/jimfs/src/main/java/com/google/common/jimfs/DirectoryEntry.java @@ -26,7 +26,7 @@ import java.nio.file.NotLinkException; import java.nio.file.Path; import java.util.Objects; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Entry in a directory, containing references to the directory itself, the file the entry links to @@ -40,11 +40,11 @@ final class DirectoryEntry { private final Directory directory; private final Name name; - @Nullable private final File file; + @NullableDecl private final File file; - @Nullable DirectoryEntry next; // for use in Directory + @NullableDecl DirectoryEntry next; // for use in Directory - DirectoryEntry(Directory directory, Name name, @Nullable File file) { + DirectoryEntry(Directory directory, Name name, @NullableDecl File file) { this.directory = checkNotNull(directory); this.name = checkNotNull(name); this.file = file; @@ -135,7 +135,7 @@ public File file() { } /** Returns the file this entry links to or {@code null} if the file does not exist */ - @Nullable + @NullableDecl public File fileOrNull() { return file; } diff --git a/jimfs/src/main/java/com/google/common/jimfs/DosAttributeProvider.java b/jimfs/src/main/java/com/google/common/jimfs/DosAttributeProvider.java index cfada16c..51bf96bd 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/DosAttributeProvider.java +++ b/jimfs/src/main/java/com/google/common/jimfs/DosAttributeProvider.java @@ -27,7 +27,7 @@ import java.nio.file.attribute.FileAttributeView; import java.nio.file.attribute.FileTime; import java.util.Map; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Attribute provider that provides the {@link DosFileAttributeView} ("dos") and allows the reading @@ -75,7 +75,7 @@ private static Boolean getDefaultValue(String attribute, Map userProv return false; } - @Nullable + @NullableDecl @Override public Object get(File file, String attribute) { if (ATTRIBUTES.contains(attribute)) { diff --git a/jimfs/src/main/java/com/google/common/jimfs/File.java b/jimfs/src/main/java/com/google/common/jimfs/File.java index d23aa983..ce1cc001 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/File.java +++ b/jimfs/src/main/java/com/google/common/jimfs/File.java @@ -25,7 +25,7 @@ import com.google.common.collect.Table; import java.io.IOException; import java.util.concurrent.locks.ReadWriteLock; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * A file object, containing both the file's metadata and content. @@ -42,7 +42,7 @@ public abstract class File { private long lastAccessTime; private long lastModifiedTime; - @Nullable // null when only the basic view is used (default) + @NullableDecl // null when only the basic view is used (default) private Table attributes; File(int id) { @@ -102,7 +102,7 @@ void copyContentTo(File file) throws IOException {} * Returns the read-write lock for this file's content, or {@code null} if there is no content * lock. */ - @Nullable + @NullableDecl ReadWriteLock contentLock() { return null; } @@ -223,7 +223,7 @@ final synchronized ImmutableSet getAttributeKeys() { } /** Gets the value of the given attribute in the given view. */ - @Nullable + @NullableDecl public final synchronized Object getAttribute(String view, String attribute) { if (attributes == null) { return null; @@ -264,7 +264,7 @@ final synchronized void copyAttributes(File target) { target.putAll(attributes); } - private synchronized void putAll(@Nullable Table attributes) { + private synchronized void putAll(@NullableDecl Table attributes) { if (attributes != null && this.attributes != attributes) { if (this.attributes == null) { this.attributes = HashBasedTable.create(); diff --git a/jimfs/src/main/java/com/google/common/jimfs/FileSystemView.java b/jimfs/src/main/java/com/google/common/jimfs/FileSystemView.java index c9ff2458..62e8739c 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/FileSystemView.java +++ b/jimfs/src/main/java/com/google/common/jimfs/FileSystemView.java @@ -48,7 +48,7 @@ import java.util.Set; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * View of a file system with a specific working directory. As all file system operations need to @@ -305,7 +305,7 @@ public RegularFile getOrCreateRegularFile( * Looks up the regular file at the given path, throwing an exception if the file isn't a regular * file. Returns null if the file did not exist. */ - @Nullable + @NullableDecl private RegularFile lookUpRegularFile(JimfsPath path, Set options) throws IOException { store.readLock().lock(); @@ -692,13 +692,13 @@ private void unlockSourceAndCopy(File sourceFile, File copyFile) { } /** Returns a file attribute view using the given lookup callback. */ - @Nullable + @NullableDecl public V getFileAttributeView(FileLookup lookup, Class type) { return store.getFileAttributeView(lookup, type); } /** Returns a file attribute view for the given path in this view. */ - @Nullable + @NullableDecl public V getFileAttributeView( final JimfsPath path, Class type, final Set options) { return store.getFileAttributeView( diff --git a/jimfs/src/main/java/com/google/common/jimfs/FileTree.java b/jimfs/src/main/java/com/google/common/jimfs/FileTree.java index 71beb0ea..93df55fa 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/FileTree.java +++ b/jimfs/src/main/java/com/google/common/jimfs/FileTree.java @@ -27,7 +27,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * The tree of directories and files for the file system. Contains the file system root directories @@ -63,7 +63,7 @@ public ImmutableSortedSet getRootDirectoryNames() { * Gets the directory entry for the root with the given name or {@code null} if no such root * exists. */ - @Nullable + @NullableDecl public DirectoryEntry getRoot(Name name) { Directory dir = roots.get(name); return dir == null ? null : dir.entryInParent(); @@ -83,7 +83,7 @@ public DirectoryEntry lookUp( return result; } - @Nullable + @NullableDecl private DirectoryEntry lookUp( File dir, JimfsPath path, Set options, int linkDepth) throws IOException { ImmutableList names = path.names(); @@ -114,7 +114,7 @@ private DirectoryEntry lookUp( * Looks up the given names against the given base file. If the file is not a directory, the * lookup fails. */ - @Nullable + @NullableDecl private DirectoryEntry lookUp( File dir, Iterable names, Set options, int linkDepth) throws IOException { @@ -151,9 +151,9 @@ private DirectoryEntry lookUp( } /** Looks up the last element of a path. */ - @Nullable + @NullableDecl private DirectoryEntry lookUpLast( - @Nullable File dir, Name name, Set options, int linkDepth) + @NullableDecl File dir, Name name, Set options, int linkDepth) throws IOException { Directory directory = toDirectory(dir); if (directory == null) { @@ -177,7 +177,7 @@ private DirectoryEntry lookUpLast( * Returns the directory entry located by the target path of the given symbolic link, resolved * relative to the given directory. */ - @Nullable + @NullableDecl private DirectoryEntry followSymbolicLink(File dir, SymbolicLink link, int linkDepth) throws IOException { if (linkDepth >= MAX_SYMBOLIC_LINK_DEPTH) { @@ -196,7 +196,7 @@ private DirectoryEntry followSymbolicLink(File dir, SymbolicLink link, int linkD * we find an entry [bar -> "." -> bar], we instead return the entry for bar in its parent, [foo * -> "bar" -> bar]. */ - @Nullable + @NullableDecl private DirectoryEntry getRealEntry(DirectoryEntry entry) { Name name = entry.name(); @@ -209,8 +209,8 @@ private DirectoryEntry getRealEntry(DirectoryEntry entry) { } } - @Nullable - private Directory toDirectory(@Nullable File file) { + @NullableDecl + private Directory toDirectory(@NullableDecl File file) { return file == null || !file.isDirectory() ? null : (Directory) file; } diff --git a/jimfs/src/main/java/com/google/common/jimfs/GuardedBy.java b/jimfs/src/main/java/com/google/common/jimfs/GuardedBy.java new file mode 100644 index 00000000..a6537362 --- /dev/null +++ b/jimfs/src/main/java/com/google/common/jimfs/GuardedBy.java @@ -0,0 +1,36 @@ +/* + * Copyright 2017 The Error Prone Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.common.jimfs; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.CLASS; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +// TODO(cpovirk): Delete this in favor of the copy in Error Prone once that has a module name. +/** Indicates that the annotated element should be used only while holding the specified lock. */ +@Target({FIELD, METHOD}) +@Retention(CLASS) +@interface GuardedBy { + /** + * The lock that should be held, specified in the format given in Java + * Concurrency in Practice. + */ + String value(); +} diff --git a/jimfs/src/main/java/com/google/common/jimfs/Jimfs.java b/jimfs/src/main/java/com/google/common/jimfs/Jimfs.java index 1a69125a..a04ce46d 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/Jimfs.java +++ b/jimfs/src/main/java/com/google/common/jimfs/Jimfs.java @@ -33,7 +33,7 @@ import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Static factory methods for creating new Jimfs file systems. File systems may either be created @@ -174,7 +174,7 @@ static FileSystem newFileSystem(URI uri, Configuration config) { * The system-loaded instance of {@code SystemJimfsFileSystemProvider}, or {@code null} if it * could not be found or loaded. */ - @Nullable static final FileSystemProvider systemProvider = getSystemJimfsProvider(); + @NullableDecl static final FileSystemProvider systemProvider = getSystemJimfsProvider(); /** * Returns the system-loaded instance of {@code SystemJimfsFileSystemProvider} or {@code null} if @@ -188,7 +188,7 @@ static FileSystem newFileSystem(URI uri, Configuration config) { * same class loader) as the class whose static cache a {@code JimfsFileSystem} instance will be * placed in when {@code FileSystems.newFileSystem} is called in {@code Jimfs.newFileSystem}. */ - @Nullable + @NullableDecl private static FileSystemProvider getSystemJimfsProvider() { try { for (FileSystemProvider provider : FileSystemProvider.installedProviders()) { diff --git a/jimfs/src/main/java/com/google/common/jimfs/JimfsAsynchronousFileChannel.java b/jimfs/src/main/java/com/google/common/jimfs/JimfsAsynchronousFileChannel.java index 9401b141..c59522c6 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/JimfsAsynchronousFileChannel.java +++ b/jimfs/src/main/java/com/google/common/jimfs/JimfsAsynchronousFileChannel.java @@ -32,7 +32,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * {@link AsynchronousFileChannel} implementation that delegates to a {@link JimfsFileChannel}. @@ -55,7 +55,9 @@ public long size() throws IOException { } private void addCallback( - ListenableFuture future, CompletionHandler handler, @Nullable A attachment) { + ListenableFuture future, + CompletionHandler handler, + @NullableDecl A attachment) { future.addListener(new CompletionHandlerCallback<>(future, handler, attachment), executor); } @@ -75,7 +77,7 @@ public void lock( long position, long size, boolean shared, - @Nullable A attachment, + @NullableDecl A attachment, CompletionHandler handler) { checkNotNull(handler); addCallback(lock(position, size, shared), handler, attachment); @@ -120,7 +122,7 @@ public FileLock tryLock(long position, long size, boolean shared) throws IOExcep public void read( ByteBuffer dst, long position, - @Nullable A attachment, + @NullableDecl A attachment, CompletionHandler handler) { addCallback(read(dst, position), handler, attachment); } @@ -146,7 +148,7 @@ public Integer call() throws IOException { public void write( ByteBuffer src, long position, - @Nullable A attachment, + @NullableDecl A attachment, CompletionHandler handler) { addCallback(write(src, position), handler, attachment); } @@ -189,12 +191,12 @@ private static final class CompletionHandlerCallback implements Runnable { private final ListenableFuture future; private final CompletionHandler completionHandler; - @Nullable private final A attachment; + @NullableDecl private final A attachment; private CompletionHandlerCallback( ListenableFuture future, CompletionHandler completionHandler, - @Nullable A attachment) { + @NullableDecl A attachment) { this.future = checkNotNull(future); this.completionHandler = checkNotNull(completionHandler); this.attachment = attachment; diff --git a/jimfs/src/main/java/com/google/common/jimfs/JimfsFileChannel.java b/jimfs/src/main/java/com/google/common/jimfs/JimfsFileChannel.java index bd4e95be..2ba46fc9 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/JimfsFileChannel.java +++ b/jimfs/src/main/java/com/google/common/jimfs/JimfsFileChannel.java @@ -43,7 +43,6 @@ import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; -import javax.annotation.concurrent.GuardedBy; /** * A {@link FileChannel} implementation that reads and writes to a {@link RegularFile} object. The diff --git a/jimfs/src/main/java/com/google/common/jimfs/JimfsFileStore.java b/jimfs/src/main/java/com/google/common/jimfs/JimfsFileStore.java index 6a99f29b..910d231e 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/JimfsFileStore.java +++ b/jimfs/src/main/java/com/google/common/jimfs/JimfsFileStore.java @@ -34,7 +34,7 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * {@link FileStore} implementation which provides methods for file creation, lookup and attribute @@ -102,7 +102,7 @@ ImmutableSortedSet getRootDirectoryNames() { } /** Returns the root directory with the given name or {@code null} if no such directory exists. */ - @Nullable + @NullableDecl Directory getRoot(Name name) { DirectoryEntry entry = tree.getRoot(name); return entry == null ? null : (Directory) entry.file(); @@ -170,7 +170,7 @@ void setInitialAttributes(File file, FileAttribute... attrs) { * Returns an attribute view of the given type for the given file lookup callback, or {@code null} * if the view type is not supported. */ - @Nullable + @NullableDecl V getFileAttributeView(FileLookup lookup, Class type) { state.checkOpen(); return attributes.getFileAttributeView(lookup, type); diff --git a/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystem.java b/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystem.java index ce85b15e..dd72146f 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystem.java +++ b/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystem.java @@ -33,7 +33,7 @@ import java.nio.file.attribute.UserPrincipalLookupService; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * {@link FileSystem} implementation for Jimfs. Most behavior for the file system is implemented by @@ -285,7 +285,7 @@ public WatchService newWatchService() throws IOException { return watchServiceConfig.newWatchService(defaultView, pathService); } - @Nullable private ExecutorService defaultThreadPool; + @NullableDecl private ExecutorService defaultThreadPool; /** * Returns a default thread pool to use for asynchronous file channels when users do not provide diff --git a/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystemProvider.java b/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystemProvider.java index 235be80d..9b32bd7f 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystemProvider.java +++ b/jimfs/src/main/java/com/google/common/jimfs/JimfsFileSystemProvider.java @@ -48,7 +48,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutorService; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * {@link FileSystemProvider} implementation for Jimfs. This provider implements the actual file @@ -170,7 +170,7 @@ public SeekableByteChannel newByteChannel( public AsynchronousFileChannel newAsynchronousFileChannel( Path path, Set options, - @Nullable ExecutorService executor, + @NullableDecl ExecutorService executor, FileAttribute... attrs) throws IOException { // call newFileChannel and cast so that FileChannel support is checked there @@ -320,7 +320,7 @@ public void checkAccess(Path path, AccessMode... modes) throws IOException { getDefaultView(checkedPath).checkAccess(checkedPath); } - @Nullable + @NullableDecl @Override public V getFileAttributeView( Path path, Class type, LinkOption... options) { diff --git a/jimfs/src/main/java/com/google/common/jimfs/JimfsInputStream.java b/jimfs/src/main/java/com/google/common/jimfs/JimfsInputStream.java index 5268573e..750530c5 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/JimfsInputStream.java +++ b/jimfs/src/main/java/com/google/common/jimfs/JimfsInputStream.java @@ -23,7 +23,6 @@ import com.google.common.primitives.Ints; import java.io.IOException; import java.io.InputStream; -import javax.annotation.concurrent.GuardedBy; /** * {@link InputStream} for reading from a file's {@link RegularFile}. diff --git a/jimfs/src/main/java/com/google/common/jimfs/JimfsOutputStream.java b/jimfs/src/main/java/com/google/common/jimfs/JimfsOutputStream.java index 5beffb1b..0b88046e 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/JimfsOutputStream.java +++ b/jimfs/src/main/java/com/google/common/jimfs/JimfsOutputStream.java @@ -22,7 +22,6 @@ import com.google.common.annotations.VisibleForTesting; import java.io.IOException; import java.io.OutputStream; -import javax.annotation.concurrent.GuardedBy; /** * {@link OutputStream} for writing to a {@link RegularFile}. diff --git a/jimfs/src/main/java/com/google/common/jimfs/JimfsPath.java b/jimfs/src/main/java/com/google/common/jimfs/JimfsPath.java index 9db767c8..7c6b115d 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/JimfsPath.java +++ b/jimfs/src/main/java/com/google/common/jimfs/JimfsPath.java @@ -41,7 +41,7 @@ import java.util.Iterator; import java.util.List; import java.util.Objects; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Jimfs implementation of {@link Path}. Creation of new {@code Path} objects is delegated to the @@ -51,18 +51,18 @@ */ final class JimfsPath implements Path { - @Nullable private final Name root; + @NullableDecl private final Name root; private final ImmutableList names; private final PathService pathService; - public JimfsPath(PathService pathService, @Nullable Name root, Iterable names) { + public JimfsPath(PathService pathService, @NullableDecl Name root, Iterable names) { this.pathService = checkNotNull(pathService); this.root = root; this.names = ImmutableList.copyOf(names); } /** Returns the root name, or null if there is no root. */ - @Nullable + @NullableDecl public Name root() { return root; } @@ -76,7 +76,7 @@ public ImmutableList names() { * Returns the file name of this path. Unlike {@link #getFileName()}, this may return the name of * the root if this is a root path. */ - @Nullable + @NullableDecl public Name name() { if (!names.isEmpty()) { return Iterables.getLast(names); @@ -421,7 +421,7 @@ public int compareTo(Path other) { } @Override - public boolean equals(@Nullable Object obj) { + public boolean equals(@NullableDecl Object obj) { return obj instanceof JimfsPath && compareTo((JimfsPath) obj) == 0; } @@ -435,7 +435,7 @@ public String toString() { return pathService.toString(this); } - @Nullable + @NullableDecl private JimfsPath checkPath(Path other) { if (checkNotNull(other) instanceof JimfsPath && other.getFileSystem().equals(getFileSystem())) { return (JimfsPath) other; diff --git a/jimfs/src/main/java/com/google/common/jimfs/JimfsSecureDirectoryStream.java b/jimfs/src/main/java/com/google/common/jimfs/JimfsSecureDirectoryStream.java index 81c15d71..e3391b67 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/JimfsSecureDirectoryStream.java +++ b/jimfs/src/main/java/com/google/common/jimfs/JimfsSecureDirectoryStream.java @@ -35,7 +35,7 @@ import java.nio.file.attribute.FileAttributeView; import java.util.Iterator; import java.util.Set; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Secure directory stream implementation that uses a {@link FileSystemView} with the stream's @@ -87,7 +87,7 @@ protected synchronized void checkOpen() { private final class DirectoryIterator extends AbstractIterator { - @Nullable private Iterator fileNames; + @NullableDecl private Iterator fileNames; @Override protected synchronized Path computeNext() { diff --git a/jimfs/src/main/java/com/google/common/jimfs/Name.java b/jimfs/src/main/java/com/google/common/jimfs/Name.java index 6ff13ea6..327be751 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/Name.java +++ b/jimfs/src/main/java/com/google/common/jimfs/Name.java @@ -21,7 +21,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.collect.Ordering; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Immutable representation of a file name. Used both for the name components of paths and as the @@ -77,7 +77,7 @@ private Name(String display, String canonical) { } @Override - public boolean equals(@Nullable Object obj) { + public boolean equals(@NullableDecl Object obj) { if (obj instanceof Name) { Name other = (Name) obj; return canonical.equals(other.canonical); diff --git a/jimfs/src/main/java/com/google/common/jimfs/OwnerAttributeProvider.java b/jimfs/src/main/java/com/google/common/jimfs/OwnerAttributeProvider.java index d1027462..34086392 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/OwnerAttributeProvider.java +++ b/jimfs/src/main/java/com/google/common/jimfs/OwnerAttributeProvider.java @@ -26,7 +26,7 @@ import java.nio.file.attribute.FileOwnerAttributeView; import java.nio.file.attribute.UserPrincipal; import java.util.Map; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Attribute provider that provides the {@link FileOwnerAttributeView} ("owner"). @@ -65,7 +65,7 @@ public ImmutableSet fixedAttributes() { return ImmutableMap.of("owner:owner", owner); } - @Nullable + @NullableDecl @Override public Object get(File file, String attribute) { if (attribute.equals("owner")) { diff --git a/jimfs/src/main/java/com/google/common/jimfs/PathService.java b/jimfs/src/main/java/com/google/common/jimfs/PathService.java index b81ebf5f..39bac91a 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/PathService.java +++ b/jimfs/src/main/java/com/google/common/jimfs/PathService.java @@ -38,7 +38,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Service for creating {@link JimfsPath} instances and handling other path-related operations. @@ -162,7 +162,7 @@ public JimfsPath createRelativePath(Iterable names) { } /** Returns a path with the given root (or no root, if null) and the given names. */ - public JimfsPath createPath(@Nullable Name root, Iterable names) { + public JimfsPath createPath(@NullableDecl Name root, Iterable names) { ImmutableList nameList = ImmutableList.copyOf(Iterables.filter(names, NOT_EMPTY)); if (root == null && nameList.isEmpty()) { // ensure the canonical empty path (one empty string name) is used rather than a path with @@ -173,7 +173,7 @@ public JimfsPath createPath(@Nullable Name root, Iterable names) { } /** Returns a path with the given root (or no root, if null) and the given names. */ - protected final JimfsPath createPathInternal(@Nullable Name root, Iterable names) { + protected final JimfsPath createPathInternal(@NullableDecl Name root, Iterable names) { return new JimfsPath(this, root, names); } diff --git a/jimfs/src/main/java/com/google/common/jimfs/PathType.java b/jimfs/src/main/java/com/google/common/jimfs/PathType.java index f27e358e..4e4d30e2 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/PathType.java +++ b/jimfs/src/main/java/com/google/common/jimfs/PathType.java @@ -26,7 +26,7 @@ import java.net.URISyntaxException; import java.nio.file.InvalidPathException; import java.util.Arrays; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * An object defining a specific type of path. Knows how to parse strings to a path and how to @@ -164,7 +164,7 @@ public String toString() { } /** Returns the string form of the given path. */ - public abstract String toString(@Nullable String root, Iterable names); + public abstract String toString(@NullableDecl String root, Iterable names); /** * Returns the string form of the given path for use in the path part of a URI. The root element @@ -211,10 +211,10 @@ public final ParseResult fromUri(URI uri) { /** Simple result of parsing a path. */ public static final class ParseResult { - @Nullable private final String root; + @NullableDecl private final String root; private final Iterable names; - public ParseResult(@Nullable String root, Iterable names) { + public ParseResult(@NullableDecl String root, Iterable names) { this.root = root; this.names = checkNotNull(names); } @@ -230,7 +230,7 @@ public boolean isRoot() { } /** Returns the parsed root element, or null if there was no root. */ - @Nullable + @NullableDecl public String root() { return root; } diff --git a/jimfs/src/main/java/com/google/common/jimfs/PosixAttributeProvider.java b/jimfs/src/main/java/com/google/common/jimfs/PosixAttributeProvider.java index bdb30c53..9dcd887e 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/PosixAttributeProvider.java +++ b/jimfs/src/main/java/com/google/common/jimfs/PosixAttributeProvider.java @@ -35,7 +35,7 @@ import java.nio.file.attribute.UserPrincipal; import java.util.Map; import java.util.Set; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Attribute provider that provides the {@link PosixFileAttributeView} ("posix") and allows reading @@ -114,7 +114,7 @@ public ImmutableSet fixedAttributes() { "posix:permissions", permissions); } - @Nullable + @NullableDecl @Override public Object get(File file, String attribute) { switch (attribute) { diff --git a/jimfs/src/main/java/com/google/common/jimfs/StandardAttributeProviders.java b/jimfs/src/main/java/com/google/common/jimfs/StandardAttributeProviders.java index 86839137..973c6bb4 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/StandardAttributeProviders.java +++ b/jimfs/src/main/java/com/google/common/jimfs/StandardAttributeProviders.java @@ -17,7 +17,7 @@ package com.google.common.jimfs; import com.google.common.collect.ImmutableMap; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Static registry of {@link AttributeProvider} implementations for the standard set of file @@ -43,7 +43,7 @@ private StandardAttributeProviders() {} * Returns the attribute provider for the given view, or {@code null} if the given view is not one * of the attribute views this supports. */ - @Nullable + @NullableDecl public static AttributeProvider get(String view) { AttributeProvider provider = PROVIDERS.get(view); diff --git a/jimfs/src/main/java/com/google/common/jimfs/UnixPathType.java b/jimfs/src/main/java/com/google/common/jimfs/UnixPathType.java index 126d8e14..76f13395 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/UnixPathType.java +++ b/jimfs/src/main/java/com/google/common/jimfs/UnixPathType.java @@ -19,7 +19,7 @@ import static com.google.common.base.Preconditions.checkArgument; import java.nio.file.InvalidPathException; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Unix-style path type. @@ -55,7 +55,7 @@ private static void checkValid(String path) { } @Override - public String toString(@Nullable String root, Iterable names) { + public String toString(@NullableDecl String root, Iterable names) { StringBuilder builder = new StringBuilder(); if (root != null) { builder.append(root); diff --git a/jimfs/src/main/java/com/google/common/jimfs/WindowsPathType.java b/jimfs/src/main/java/com/google/common/jimfs/WindowsPathType.java index 0e68b263..7cdf0c40 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/WindowsPathType.java +++ b/jimfs/src/main/java/com/google/common/jimfs/WindowsPathType.java @@ -20,7 +20,7 @@ import java.util.Iterator; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Windows-style path type. @@ -134,7 +134,7 @@ private String parseUncRoot(String path, String original) { private static final Pattern DRIVE_LETTER_ROOT = Pattern.compile("^[a-zA-Z]:\\\\"); /** Parses a normal drive-letter root, e.g. "C:\". */ - @Nullable + @NullableDecl private String parseDriveRoot(String path) { Matcher drivePathMatcher = DRIVE_LETTER_ROOT.matcher(path); if (drivePathMatcher.find()) { @@ -160,7 +160,7 @@ private static boolean isReserved(char c) { } @Override - public String toString(@Nullable String root, Iterable names) { + public String toString(@NullableDecl String root, Iterable names) { StringBuilder builder = new StringBuilder(); if (root != null) { builder.append(root); diff --git a/jimfs/src/test/java/com/google/common/jimfs/AbstractPathMatcherTest.java b/jimfs/src/test/java/com/google/common/jimfs/AbstractPathMatcherTest.java index 79b39469..70ac0e99 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/AbstractPathMatcherTest.java +++ b/jimfs/src/test/java/com/google/common/jimfs/AbstractPathMatcherTest.java @@ -33,7 +33,7 @@ import java.nio.file.WatchService; import java.util.Iterator; import java.util.regex.PatternSyntaxException; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Abstract base class for tests of {@link PathMatcher} implementations. @@ -48,7 +48,7 @@ public abstract class AbstractPathMatcherTest { protected abstract PathMatcher matcher(String pattern); /** Override to return a real matcher for the given pattern. */ - @Nullable + @NullableDecl protected PathMatcher realMatcher(String pattern) { return null; } @@ -77,7 +77,7 @@ protected final class PatternAsserter { private final PathMatcher matcher; - @Nullable private final PathMatcher realMatcher; + @NullableDecl private final PathMatcher realMatcher; PatternAsserter(String pattern) { this.matcher = matcher(pattern); diff --git a/jimfs/src/test/java/com/google/common/jimfs/DirectoryTest.java b/jimfs/src/test/java/com/google/common/jimfs/DirectoryTest.java index 03f7f6a2..217509d0 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/DirectoryTest.java +++ b/jimfs/src/test/java/com/google/common/jimfs/DirectoryTest.java @@ -28,7 +28,7 @@ import com.google.common.collect.Iterables; import java.util.HashSet; import java.util.Set; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -365,7 +365,7 @@ private static DirectoryEntry entry(String name) { return new DirectoryEntry(A, Name.simple(name), A); } - private static DirectoryEntry entry(Directory dir, String name, @Nullable File file) { + private static DirectoryEntry entry(Directory dir, String name, @NullableDecl File file) { return new DirectoryEntry(dir, Name.simple(name), file); } diff --git a/jimfs/src/test/java/com/google/common/jimfs/FileTreeTest.java b/jimfs/src/test/java/com/google/common/jimfs/FileTreeTest.java index 9390a5d5..54f590d2 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/FileTreeTest.java +++ b/jimfs/src/test/java/com/google/common/jimfs/FileTreeTest.java @@ -31,7 +31,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Random; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -87,7 +87,7 @@ public ParseResult parsePath(String path) { } @Override - public String toString(@Nullable String root, Iterable names) { + public String toString(@NullableDecl String root, Iterable names) { root = Strings.nullToEmpty(root); return root + Joiner.on('/').join(names); } diff --git a/jimfs/src/test/java/com/google/common/jimfs/PathSubject.java b/jimfs/src/test/java/com/google/common/jimfs/PathSubject.java index 5cbe3ddf..f6927a5e 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/PathSubject.java +++ b/jimfs/src/test/java/com/google/common/jimfs/PathSubject.java @@ -36,7 +36,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * Subject for doing assertions on file system paths. @@ -103,7 +103,7 @@ public PathSubject isRelative() { } /** Asserts that the path has the given root component. */ - public PathSubject hasRootComponent(@Nullable String root) { + public PathSubject hasRootComponent(@NullableDecl String root) { Path rootComponent = actual.getRoot(); if (root == null && rootComponent != null) { failWithActual("expected to have root component", root); diff --git a/jimfs/src/test/java/com/google/common/jimfs/PathTypeTest.java b/jimfs/src/test/java/com/google/common/jimfs/PathTypeTest.java index dd649401..59fc1142 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/PathTypeTest.java +++ b/jimfs/src/test/java/com/google/common/jimfs/PathTypeTest.java @@ -22,7 +22,7 @@ import com.google.common.collect.ImmutableList; import java.net.URI; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -94,7 +94,7 @@ public void testUriRoundTrips() { assertUriRoundTripsCorrectly(type, "$foo/bar baz"); } - static void assertParseResult(ParseResult result, @Nullable String root, String... names) { + static void assertParseResult(ParseResult result, @NullableDecl String root, String... names) { assertThat(result.root()).isEqualTo(root); assertThat(result.names()).containsExactly((Object[]) names).inOrder(); } @@ -126,7 +126,7 @@ public ParseResult parsePath(String path) { } @Override - public String toString(@Nullable String root, Iterable names) { + public String toString(@NullableDecl String root, Iterable names) { StringBuilder builder = new StringBuilder(); if (root != null) { builder.append(root); diff --git a/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java b/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java index 9dbeee9f..4518132a 100644 --- a/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java +++ b/jimfs/src/test/java/com/google/common/jimfs/TestAttributeProvider.java @@ -26,7 +26,7 @@ import java.nio.file.attribute.FileTime; import java.util.HashMap; import java.util.Map; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** @author Colin Decker */ public final class TestAttributeProvider extends AttributeProvider { @@ -133,9 +133,9 @@ public Attributes readAttributes() throws IOException { @Override public void setTimes( - @Nullable FileTime lastModifiedTime, - @Nullable FileTime lastAccessTime, - @Nullable FileTime createTime) + @NullableDecl FileTime lastModifiedTime, + @NullableDecl FileTime lastAccessTime, + @NullableDecl FileTime createTime) throws IOException { basicView.setTimes(lastModifiedTime, lastAccessTime, createTime); } diff --git a/pom.xml b/pom.xml index 6c0187b6..32e13bce 100644 --- a/pom.xml +++ b/pom.xml @@ -117,6 +117,11 @@ jsr305 3.0.2 + + org.checkerframework + checker-compat-qual + 2.5.5 +