Skip to content

Commit

Permalink
Mostly migrate off jsr305.
Browse files Browse the repository at this point in the history
- Mostly migrate to Checker Framework declaration annotations.
- Migrate @GuardedBy to a custom annotation for now. (We would migrate to Error Prone's, but that's causing me problems as I experiment with JPMS.)

Compare to b/69411537 for Guava.

I've left @ParametersAreNonnullByDefault in place for now, but we'd need to remove it to fully eliminate the jsr305 dep.

RELNOTES=Migrated from jsr305 `@Nullable` to Checker Framework `@NullableDecl`. In addition to the new dependency on the Checker Framework annotations, we keep the dependency on jsr305 for now so that we can keep using `@ParametersAreNonNullByDefault`.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=272713254
  • Loading branch information
cpovirk committed Oct 4, 2019
1 parent 3bac6e0 commit a76d68f
Show file tree
Hide file tree
Showing 39 changed files with 164 additions and 119 deletions.
5 changes: 5 additions & 0 deletions jimfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<artifactId>jsr305</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-compat-qual</artifactId>
<optional>true</optional>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,14 +90,14 @@ ImmutableList<WatchKey> 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();
Expand All @@ -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);
Expand Down Expand Up @@ -142,9 +142,9 @@ static final class Event<T> implements WatchEvent<T> {
private final Kind<T> kind;
private final int count;

@Nullable private final T context;
@NullableDecl private final T context;

public Event(Kind<T> kind, int count, @Nullable T context) {
public Event(Kind<T> kind, int count, @NullableDecl T context) {
this.kind = checkNotNull(kind);
checkArgument(count >= 0, "count (%s) must be non-negative", count);
this.count = count;
Expand All @@ -161,7 +161,7 @@ public int count() {
return count;
}

@Nullable
@NullableDecl
@Override
public T context() {
return context;
Expand Down Expand Up @@ -214,7 +214,7 @@ private static WatchEvent<Object> overflowEvent(int count) {

public Key(
AbstractWatchService watcher,
@Nullable Watchable watchable,
@NullableDecl Watchable watchable,
Iterable<? extends WatchEvent.Kind<?>> subscribedTypes) {
this.watcher = checkNotNull(watcher);
this.watchable = watchable; // nullable for Watcher poison
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down Expand Up @@ -71,7 +71,7 @@ public ImmutableSet<String> fixedAttributes() {
return ImmutableMap.of("acl:acl", acl);
}

@Nullable
@NullableDecl
@Override
public Object get(File file, String attribute) {
if (attribute.equals("acl")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -87,7 +87,7 @@ public ImmutableSet<String> 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);

/**
Expand All @@ -108,7 +108,7 @@ public ImmutableSet<String> 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<? extends BasicFileAttributes> attributesType() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -259,7 +259,7 @@ private void setAttributeInternal(
* if the view type is not supported.
*/
@SuppressWarnings("unchecked")
@Nullable
@NullableDecl
public <V extends FileAttributeView> V getFileAttributeView(FileLookup lookup, Class<V> type) {
AttributeProvider provider = providersByViewType.get(type);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -434,7 +434,7 @@ private ImmutableSet<PathNormalization> 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");
Expand Down
6 changes: 3 additions & 3 deletions jimfs/src/main/java/com/google/common/jimfs/Directory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -334,7 +334,7 @@ DirectoryEntry remove(Name name) {
public Iterator<DirectoryEntry> iterator() {
return new AbstractIterator<DirectoryEntry>() {
int index;
@Nullable DirectoryEntry entry;
@NullableDecl DirectoryEntry entry;

@Override
protected DirectoryEntry computeNext() {
Expand Down
10 changes: 5 additions & 5 deletions jimfs/src/main/java/com/google/common/jimfs/DirectoryEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,7 +75,7 @@ private static Boolean getDefaultValue(String attribute, Map<String, ?> userProv
return false;
}

@Nullable
@NullableDecl
@Override
public Object get(File file, String attribute) {
if (ATTRIBUTES.contains(attribute)) {
Expand Down
10 changes: 5 additions & 5 deletions jimfs/src/main/java/com/google/common/jimfs/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<String, String, Object> attributes;

File(int id) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -223,7 +223,7 @@ final synchronized ImmutableSet<String> 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;
Expand Down Expand Up @@ -264,7 +264,7 @@ final synchronized void copyAttributes(File target) {
target.putAll(attributes);
}

private synchronized void putAll(@Nullable Table<String, String, Object> attributes) {
private synchronized void putAll(@NullableDecl Table<String, String, Object> attributes) {
if (attributes != null && this.attributes != attributes) {
if (this.attributes == null) {
this.attributes = HashBasedTable.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<OpenOption> options)
throws IOException {
store.readLock().lock();
Expand Down Expand Up @@ -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 extends FileAttributeView> V getFileAttributeView(FileLookup lookup, Class<V> type) {
return store.getFileAttributeView(lookup, type);
}

/** Returns a file attribute view for the given path in this view. */
@Nullable
@NullableDecl
public <V extends FileAttributeView> V getFileAttributeView(
final JimfsPath path, Class<V> type, final Set<? super LinkOption> options) {
return store.getFileAttributeView(
Expand Down
Loading

0 comments on commit a76d68f

Please sign in to comment.