Skip to content

Commit

Permalink
Add @Nullable to the return declaration of methods that can clearly…
Browse files Browse the repository at this point in the history
… return null.

PiperOrigin-RevId: 473014878
  • Loading branch information
cpovirk authored and Jimfs Team committed Sep 8, 2022
1 parent 7962d7e commit cde6051
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public ImmutableSet<String> fixedAttributes() {
return ATTRIBUTES;
}

@NullableDecl
@Override
public Object get(File file, String attribute) {
switch (attribute) {
Expand Down
2 changes: 2 additions & 0 deletions jimfs/src/main/java/com/google/common/jimfs/Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* {@link URLStreamHandler} implementation for jimfs. Named {@code Handler} so that the class can be
Expand Down Expand Up @@ -79,6 +80,7 @@ protected URLConnection openConnection(URL url) throws IOException {
return new PathURLConnection(url);
}

@NullableDecl
@Override
@SuppressWarnings("UnsynchronizedOverridesSynchronized") // no need to synchronize to return null
protected InetAddress getHostAddress(URL url) {
Expand Down
3 changes: 3 additions & 0 deletions jimfs/src/main/java/com/google/common/jimfs/JimfsPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public boolean isAbsolute() {
return root != null;
}

@NullableDecl
@Override
public JimfsPath getRoot() {
if (root == null) {
Expand All @@ -119,11 +120,13 @@ public JimfsPath getRoot() {
return pathService.createRoot(root);
}

@NullableDecl
@Override
public JimfsPath getFileName() {
return names.isEmpty() ? null : getName(names.size() - 1);
}

@NullableDecl
@Override
public JimfsPath getParent() {
if (names.isEmpty() || (names.size() == 1 && root == null)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* {@code URLConnection} implementation.
Expand Down Expand Up @@ -133,6 +134,7 @@ public Map<String, List<String>> getHeaderFields() {
return (ImmutableMap<String, List<String>>) (ImmutableMap<String, ?>) headers.asMap();
}

@NullableDecl
@Override
public String getHeaderField(String name) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Attribute provider that provides the "unix" attribute view.
Expand Down Expand Up @@ -94,6 +95,7 @@ private Integer getUniqueId(Object object) {
return id;
}

@NullableDecl
@SuppressWarnings("unchecked")
@Override
public Object get(File file, String attribute) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.nio.file.attribute.FileAttributeView;
import java.nio.file.attribute.UserDefinedFileAttributeView;
import java.util.List;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Attribute provider that provides the {@link UserDefinedFileAttributeView} ("user"). Unlike most
Expand Down Expand Up @@ -68,6 +69,7 @@ private static ImmutableSet<String> userDefinedAttributes(File file) {
return builder.build();
}

@NullableDecl
@Override
public Object get(File file, String attribute) {
Object value = file.getAttribute("user", attribute);
Expand Down

0 comments on commit cde6051

Please sign in to comment.