File: VarargsNullness.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 (53 lines) | stat: -rw-r--r-- 1,451 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import org.checkerframework.checker.nullness.qual.*;

public class VarargsNullness {

    public void test(@NonNull Object @NonNull ... o) {
        for (@NonNull Object p : o) {
            System.out.println(p);
        }
    }

    public void test2(Object o1, Object o2) {
        System.out.println(o1);
        System.out.println(o2);
    }

    public void testVarargs() {
        test("foo", "bar", "baz");
    }

    public void testVarargsNoArgs() {
        test();
    }

    public void testNonVarargs() {
        test2("foo", "bar");
    }

    public void format1(java.lang.String a1, java.lang.@Nullable Object... a2) {
        int x = a2.length; // no warning
        // :: error: (enhancedfor.type.incompatible)
        for (@NonNull Object p : a2) // warning
        System.out.println(p);
    }

    public void format2(java.lang.String a1, java.lang.Object @Nullable ... a2) {
        // :: error: (dereference.of.nullable)
        int x = a2.length; // warning
        for (@NonNull Object p : a2) // no warning
        System.out.println(p);
    }

    public void testPrintf() {
        String s = null;
        printf("%s", s);
        // tests do not use annotated jdk
        // System.out.printf ("%s", s);
    }

    // printf declaration is taken from PrintStream
    public java.io.PrintStream printf(java.lang.String a1, java.lang.@Nullable Object... a2) {
        throw new RuntimeException("skeleton method");
    }
}