File: ParameterExpression.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 (113 lines) | stat: -rw-r--r-- 4,196 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
import java.util.Map;
import org.checkerframework.checker.nullness.qual.*;

public class ParameterExpression {
    public void m1(
            @Nullable Object o, @Nullable Object o1, @Nullable Object o2, @Nullable Object o3) {
        // :: error: (flowexpr.parse.error.postcondition)
        m2(o);
        // :: error: (dereference.of.nullable)
        o.toString();
        m3(o);
        o.toString();
        m4(o1, o2, o3);
        // :: error: (dereference.of.nullable)
        o1.toString();
        // :: error: (dereference.of.nullable)
        o2.toString();
        o3.toString();
    }

    @SuppressWarnings("assert.postcondition.not.satisfied")
    // "#0" is illegal syntax; it should be "#1"
    @EnsuresNonNull("#0")
    // :: error: (flowexpr.parse.error)
    public void m2(final @Nullable Object o) {}

    @SuppressWarnings("contracts.postcondition.not.satisfied")
    @EnsuresNonNull("#1")
    public void m3(final @Nullable Object o) {}

    @SuppressWarnings("contracts.postcondition.not.satisfied")
    @EnsuresNonNull("#3")
    public void m4(@Nullable Object x1, @Nullable Object x2, final @Nullable Object x3) {}

    // Formal parameter names should not be used on pre/postcondition, conditional postcondition
    // and formal parameter annotations in the same method declaration as the formal parameter
    // being referred. In this case, "#paramNum" should be used. This is because
    // the parameter names are not saved in bytecode.

    @Nullable Object field = null;

    // Postconditions
    @EnsuresNonNull("field") // OK
    public void m5() {
        field = new Object();
    }

    @EnsuresNonNull("param")
    // :: error: (flowexpr.parse.error)
    // :: warning: (contracts.postcondition.expression.parameter.name)
    public void m6(Object param) {
        param = new Object();
    }

    // Warning issued. 'field' is a field, but in this case what matters is that it is the name of a
    // formal parameter.
    @EnsuresNonNull("field")
    // The user can write "#1" if they meant the formal parameter, and "this.field" if they meant
    // the field.
    // :: error: (contracts.postcondition.not.satisfied)
    // :: warning: (contracts.postcondition.expression.parameter.name)
    public void m7(Object field) {
        field = new Object();
    }

    // Preconditions
    @RequiresNonNull("field") // OK
    public void m8() {}

    @RequiresNonNull("param")
    // :: error: (flowexpr.parse.error)
    // :: warning: (contracts.precondition.expression.parameter.name)
    public void m9(Object param) {}

    // Warning issued. 'field' is a field, but in this case what matters is that it is the name of a
    // formal parameter.
    @RequiresNonNull("field")
    // The user can write "#1" if they meant the formal parameter, and "this.field" if they meant
    // the field.
    // :: warning: (contracts.precondition.expression.parameter.name)
    public void m10(Object field) {}

    // Conditional postconditions
    @EnsuresNonNullIf(result = true, expression = "field") // OK
    public boolean m11() {
        field = new Object();
        return true;
    }

    @EnsuresNonNullIf(result = true, expression = "param")
    // :: error: (flowexpr.parse.error)
    // :: warning: (contracts.conditional.postcondition.expression.parameter.name)
    public boolean m12(Object param) {
        param = new Object();
        return true;
    }

    // Warning issued. 'field' is a field, but in this case what matters is that it is the name of a
    // formal parameter.
    @EnsuresNonNullIf(result = true, expression = "field")
    // The user can write "#1" if they meant the formal parameter, and "this.field" if they meant
    // the field.
    // :: warning: (contracts.conditional.postcondition.expression.parameter.name)
    public boolean m13(Object field) {
        field = new Object();
        // :: error: (contracts.conditional.postcondition.not.satisfied)
        return true;
    }

    // Annotations on formal parameters referring to a formal parameter of the same method.
    // :: error: (expression.unparsable.type.invalid)
    public void m14(@KeyFor("param2") Object param1, Map<Object, Object> param2) {}
}