File: Issue2302.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 (25 lines) | stat: -rw-r--r-- 1,079 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
// Test case for Issue 2302
// https://github.com/typetools/checker-framework/issues/2302

@SuppressWarnings("unchecked")
class Issue2302 {
    static class StrangeConstructorTypeArgs<V> {
        // The constructor does not use the type parameter V.
        public StrangeConstructorTypeArgs(MyClass<byte[]> abs) {}
    }

    static class MyClass<VALUE> {}

    static StrangeConstructorTypeArgs getStrangeConstructorTypeArgs() {
        // Crash with the diamond operator.
        // Type inference chooses `Object` as the type argument.
        // That is a bug, since it should choose exactly `byte[]`.
        return new StrangeConstructorTypeArgs(new MyClass<>());

        // No crash with an explicit type argument (no diamond operator), no matter what it is.
        // return new StrangeConstructorTypeArgs(new MyClass<byte[]>());
        // return new StrangeConstructorTypeArgs(new MyClass<Integer>());
        // return new StrangeConstructorTypeArgs(new MyClass<Object>());
        // return new StrangeConstructorTypeArgs(new MyClass<@Tainted Object>());
    }
}