Skip to content

Commit

Permalink
Annotate java.lang.reflect.Array for nullness. (typetools#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpovirk authored Sep 25, 2023
1 parent 75b4b69 commit 24c35dd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/java.base/share/classes/java/lang/reflect/Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import org.checkerframework.checker.index.qual.LengthOf;
import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.interning.qual.UsesObjectEquals;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.common.value.qual.StaticallyExecutable;
import org.checkerframework.framework.qual.CFComment;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.dataflow.qual.SideEffectFree;
import org.checkerframework.framework.qual.AnnotatedFor;
Expand All @@ -47,7 +49,7 @@
* @author Nakul Saraiya
* @since 1.1
*/
@AnnotatedFor({"index", "interning"})
@AnnotatedFor({"index", "interning", "nullness"})
public final
@UsesObjectEquals class Array {

Expand Down Expand Up @@ -157,7 +159,7 @@ public static Object newInstance(Class<?> componentType, @NonNegative int... dim
* length of the specified array
*/
@Pure
public static native Object get(Object array, @IndexFor({"#1"}) int index)
public static native @Nullable Object get(Object array, @IndexFor({"#1"}) int index)
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;

/**
Expand Down Expand Up @@ -345,6 +347,9 @@ public static native double getDouble(Object array, @IndexFor({"#1"}) int index)
* argument is negative, or if it is greater than or equal to
* the length of the specified array
*/
@CFComment({"nullness: The passed array might or might not be annotated to allow nullable",
"values. We don't know which, so we conservatively issue a warning when someone passes null.",
"Compare Method.invoke."})
public static native void set(Object array, @IndexFor({"#1"}) int index, Object value)
throws IllegalArgumentException, ArrayIndexOutOfBoundsException;

Expand Down

0 comments on commit 24c35dd

Please sign in to comment.