File: TargetType63.java

package info (click to toggle)
libnb-javaparser-java 9%2B2018-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 65,320 kB
  • sloc: java: 440,096; xml: 6,359; sh: 865; makefile: 314
file content (40 lines) | stat: -rw-r--r-- 1,229 bytes parent folder | download | duplicates (19)
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
/*
 * @test /nodynamiccopyright/
 * @summary smoke test for inference of throws type variables
 * @compile/fail/ref=TargetType63.out -XDrawDiagnostics TargetType63.java
 */
class TargetType63 {

    interface F<T extends Throwable> {
        void m() throws T;
    }

    void g1() { }
    void g2() throws ClassNotFoundException { }
    void g3() throws Exception { }

    <Z extends Throwable> void m1(F<Z> fz) throws Z { }
    <Z extends ClassNotFoundException> void m2(F<Z> fz) throws Z { }

    void test1() {
        m1(()->{ }); //ok (Z = RuntimeException)
        m1(this::g1); //ok (Z = RuntimeException)
    }

    void test2() {
        m2(()->{ }); //fail (Z = ClassNotFoundException)
        m2(this::g1); //fail (Z = ClassNotFoundException)
    }

    void test3() {
        m1(()->{ throw new ClassNotFoundException(); }); //fail (Z = ClassNotFoundException)
        m1(this::g2); //fail (Z = ClassNotFoundException)
        m2(()->{ throw new ClassNotFoundException(); }); //fail (Z = ClassNotFoundException)
        m2(this::g2); //fail (Z = ClassNotFoundException)
    }

    void test4() {
        m1(()->{ throw new Exception(); }); //fail (Z = Exception)
        m1(this::g3); //fail (Z = Exception)
    }
}