alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (T7015430.java)

This example Java source code file (T7015430.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

exception, foo, iterable, runtimeexception, t7015430

The T7015430.java Java example source code

/*
 * @test /nodynamiccopyright/
 * @bug 7015430
 *
 * @summary  Incorrect thrown type determined for unchecked invocations
 * @author Daniel Smith
 * @compile/fail/ref=T7015430_1.out -source 7 -Xlint:-options,unchecked -XDrawDiagnostics T7015430.java
 * @compile/fail/ref=T7015430_2.out -Xlint:unchecked -XDrawDiagnostics T7015430.java
 *
 */

class T7015430 {
    static <E extends Exception> Iterable empty(Iterable arg) throws E {
        return null;
    }

    <E extends Exception> T7015430(Iterable arg) throws E { }

    static <E extends Exception> Iterable empty2(Iterable x) throws E {
        return null;
    }

    static class Foo<X extends Exception> {
        Foo() throws X {}
    }

    /**
    * Method invocation, no unchecked
    * inferred: RuntimeException - should pass
    */
    void m1() {
        Iterable<RuntimeException> i = java.util.Collections.emptyList();
        empty(i);
    }

    /**
    * Method invocation, unchecked, inferred arguments
    * inferred: Exception - should fail
    */
    void m2() {
        Iterable i = java.util.Collections.EMPTY_LIST;
        empty(i);
    }

    /**
    * Method invocation, unchecked, explicit arguments
    * inferred: RuntimeException - should pass
    */
    void m3() {
        Iterable i = java.util.Collections.EMPTY_LIST;
        T7015430.<RuntimeException>empty(i);
    }

    /**
    * Constructor invocation, no unchecked
    * inferred: RuntimeException - should pass
    */
    void m4() {
        Iterable<RuntimeException> i = java.util.Collections.emptyList();
        new T7015430(i);
    }

    /**
    * Constructor invocation, unchecked, inferred arguments
    * inferred: Exception - should fail
    */
    void m5() {
        Iterable i = java.util.Collections.EMPTY_LIST;
        new T7015430(i);
    }

    /**
    * Constructor invocation, unchecked, explicit arguments
    * inferred: RuntimeException - should pass
    */
    void m6() {
        Iterable i = java.util.Collections.EMPTY_LIST;
        new <RuntimeException>T7015430(i);
    }

    /**
    * Method invocation, no unchecked, inferred arguments
    * inferred: RuntimeException - should pass
    */
    void m7() {
        Iterable i = java.util.Collections.EMPTY_LIST;
        Iterable<RuntimeException> e = empty2(i);
    }

    /**
    * Method invocation, no unchecked, inferred arguments
    * inferred: Exception - should fail
    */
    void m8() {
        Iterable i = java.util.Collections.EMPTY_LIST;
        empty2(i);
    }

    /**
    * Constructor invocation, unchecked, explicit arguments
    * inferred: RuntimeException - should pass
    */
    void m9() {
        Iterable i = java.util.Collections.EMPTY_LIST;
        new <RuntimeException> T7015430(i);
    }

    /**
    * Constructor invocation, unchecked, inferred arguments
    * inferred: Exception - should fail
    */
    void m10() {
        Iterable i = java.util.Collections.EMPTY_LIST;
        new T7015430(i);
    }

    /**
    * Constructor invocation, no unchecked, inferred arguments (diamond)
    * inferred: RuntimeException - should pass
    */
    void m11() {
        Foo<RuntimeException>  o = new Foo<>();
    }

    /**
    * Constructor invocation, no unchecked, inferred arguments (diamond)
    * inferred: Exception - should fail
    */
    void m12() {
        new Foo<>();
    }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java T7015430.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.