File: ConstructorTest.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 (68 lines) | stat: -rw-r--r-- 2,384 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
import java.lang.reflect.Constructor;
import testlib.reflection.qual.Sibling1;
import testlib.reflection.qual.Sibling2;
import testlib.reflection.qual.Top;

class ConstructorTest {
    @Sibling1 int sibling1;
    @Sibling2 int sibling2;

    // :: error: (super.invocation.invalid) :: warning: (inconsistent.constructor.type)
    public @Sibling1 ConstructorTest(@Sibling1 int a) {}

    // :: error: (super.invocation.invalid) :: warning: (inconsistent.constructor.type)
    public @Sibling2 ConstructorTest(@Sibling2 int a, @Sibling2 int b) {}

    public void pass1() {
        try {
            Class<?> c = Class.forName("ConstructorTest");
            Constructor<?> init = c.getConstructor(new Class<?>[] {Integer.class});
            @Sibling1 int i = sibling1;
            @Sibling1 Object o = init.newInstance(i);
        } catch (Exception ignore) {
        }
    }

    public void pass2() {
        try {
            Class<?> c = Class.forName("ConstructorTest");
            Constructor<?> init = c.getConstructor(new Class<?>[] {Integer.class, Integer.class});
            @Sibling2 int a = sibling2;
            int b = a;
            @Top Object inst = init.newInstance(a, b);
        } catch (Exception ignore) {
        }
    }

    public void fail1() {
        try {
            Class<?> c = ConstructorTest.class;
            Constructor<?> init = c.getConstructor(new Class<?>[] {Integer.class});
            // :: error: (argument.type.incompatible)
            Object o = init.newInstance(sibling2);
        } catch (Exception ignore) {
        }
    }

    public void fail2() {
        try {
            Class<?> c = ConstructorTest.class;
            Constructor<?> init = c.getConstructor(new Class<?>[] {Integer.class});
            // :: error: (assignment.type.incompatible)
            @Sibling1 Object o = init.newInstance(new Object[] {sibling2});
        } catch (Exception ignore) {
        }
    }

    public void fail3() {
        try {
            Class<?> c = Class.forName("ConstructorTest");
            Constructor<?> init = c.getConstructor(new Class<?>[] {Integer.class, Integer.class});
            @Sibling2 int a = sibling2;
            @Sibling1 int b = sibling1;
            // :: error: (argument.type.incompatible)
            @Sibling2 Object inst = init.newInstance(a, b);
        } catch (Exception ignore) {
        }
    }
}