File: ArrayArgs.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,104 kB
  • sloc: java: 145,916; xml: 839; sh: 518; makefile: 404; perl: 26
file content (32 lines) | stat: -rw-r--r-- 1,137 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import org.checkerframework.checker.nullness.qual.*;

@org.checkerframework.framework.qual.DefaultQualifier(Nullable.class)
public class ArrayArgs {

    public void test(@NonNull String[] args) {}

    public void test(Class<@NonNull ? extends java.lang.annotation.Annotation> cls) {}

    public void test() {
        test(NonNull.class);

        String[] s1 = new String[] {null, null, null};
        // :: error: (argument.type.incompatible)
        test(s1);
        String[] s2 = new String[] {"hello", null, "goodbye"};
        // :: error: (argument.type.incompatible)
        test(s2);
        // :: error: (assignment.type.incompatible)
        @NonNull String[] s3 = new String[] {"hello", null, "goodbye"};
        // :: error: (new.array.type.invalid)
        @NonNull String[] s4 = new String[3];

        // TODO: when issue 25 is fixed, the following is safe
        // and no error needs to be raised.
        String[] s5 = new String[] {"hello", "goodbye"};
        // :: error: (argument.type.incompatible)
        test(s5);
        @NonNull String[] s6 = new String[] {"hello", "goodbye"};
        test(s6);
    }
}