File: ThrowCatchTest.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 22,840 kB
  • sloc: java: 145,910; xml: 839; sh: 518; makefile: 401; perl: 26
file content (127 lines) | stat: -rw-r--r-- 3,473 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import java.util.List;
import org.checkerframework.checker.guieffect.qual.AlwaysSafe;
import org.checkerframework.checker.guieffect.qual.PolyUIType;
import org.checkerframework.checker.guieffect.qual.UI;

class ThrowCatchTest {
    // Default type of List's type parameter is below @UI so these
    // fields are type.argument.incompatible
    // :: error: (type.argument.type.incompatible)
    List<? extends @UI Object> ooo;

    // :: error: (type.argument.type.incompatible) :: error: (type.invalid.annotations.on.use)
    List<? extends @UI Inner> iii;

    class Inner {}

    boolean flag = true;
    // Type var test
    <E extends @UI PolyUIException> void throwTypeVarUI1(E ex1, @UI E ex2) throws PolyUIException {
        if (flag) {
            // :: error: (throw.type.invalid)
            throw ex1;
        }
        // :: error: (throw.type.invalid)
        throw ex2;
    }

    <@UI E extends @UI PolyUIException> void throwTypeVarUI2(E ex1) throws PolyUIException {
        // :: error: (throw.type.invalid)
        throw ex1;
    }

    <E extends @AlwaysSafe PolyUIException> void throwTypeVarAlwaysSafe1(E ex1, @AlwaysSafe E ex2)
            throws PolyUIException {
        if (flag) {
            throw ex1;
        }
        throw ex2;
    }

    <@AlwaysSafe E extends PolyUIException> void throwTypeVarAlwaysSafe2(E ex1, @AlwaysSafe E ex2)
            throws PolyUIException {
        if (flag) {
            throw ex1;
        }
        throw ex2;
    }

    <@AlwaysSafe E extends @UI PolyUIException> void throwTypeVarMixed(E ex1, @AlwaysSafe E ex2)
            throws PolyUIException {
        if (flag) {
            // :: error: (throw.type.invalid)
            throw ex1;
        }
        throw ex2;
    }

    // Wildcards
    void throwWildcard(
            // :: error: (type.argument.type.incompatible)
            List<? extends @UI PolyUIException>
                    ui, // Default type of List's type parameter is below @UI so this is
            // type.argument.incompatible
            List<? extends @AlwaysSafe PolyUIException> alwaysSafe)
            throws PolyUIException {
        if (flag) {
            // :: error: (throw.type.invalid)
            throw ui.get(0);
        }
        throw alwaysSafe.get(0);
    }

    void throwNull() {
        throw null;
    }

    // Declared
    @UI PolyUIException ui = new PolyUIException();
    @AlwaysSafe PolyUIException alwaysSafe = new PolyUIException();

    void throwDeclared() {
        try {
            // :: error: (throw.type.invalid)
            throw ui;
        } catch (@UI PolyUIException UIParam) {

        }

        try {
            throw alwaysSafe;
        } catch (@AlwaysSafe PolyUIException alwaysSafeParam) {

        }
    }

    // Test Exception parameters
    void unionTypes() {
        try {
        } catch (
                @AlwaysSafe NullPointerPolyUIException
                | @AlwaysSafe ArrayStorePolyUIException unionParam) {

        }

        try {
        } catch (@UI NullPointerPolyUIException | @UI ArrayStorePolyUIException unionParam) {

        }
    }

    void defaults() {
        try {
            throw new PolyUIException();
        } catch (PolyUIException e) {

        }
    }

    @PolyUIType
    class PolyUIException extends Exception {}

    @PolyUIType
    class NullPointerPolyUIException extends NullPointerException {}

    @PolyUIType
    class ArrayStorePolyUIException extends ArrayStoreException {}
}