8012242: Lambda compatibility and checked exceptions

Wed, 17 Jul 2013 14:04:01 +0100

author
mcimadamore
date
Wed, 17 Jul 2013 14:04:01 +0100
changeset 1896
44e27378f523
parent 1895
37031963493e
child 1897
866c87c01285

8012242: Lambda compatibility and checked exceptions
Summary: Inference variables in 'throws' clause with no constraints should be inferred as RuntimeException
Reviewed-by: jjg, vromero

src/share/classes/com/sun/tools/javac/code/Flags.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Infer.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/MemberEnter.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6723444/T6723444.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/6723444/T6723444.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/6723444/T6723444_1.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/6723444/T6723444_2.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/7015430/T7015430.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/7015430/T7015430.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/7015430/T7015430_1.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/7015430/T7015430_2.out file | annotate | diff | comparison | revisions
test/tools/javac/lambda/TargetType63.java file | annotate | diff | comparison | revisions
test/tools/javac/lambda/TargetType63.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Flags.java	Fri Jul 12 13:11:12 2013 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java	Wed Jul 17 14:04:01 2013 +0100
     1.3 @@ -261,6 +261,11 @@
     1.4       */
     1.5      public static final long SIGNATURE_POLYMORPHIC = 1L<<46;
     1.6  
     1.7 +    /**
     1.8 +     * Flag that marks inference variables used in a 'throws' clause
     1.9 +     */
    1.10 +    public static final long THROWS = 1L<<47;
    1.11 +
    1.12      /** Modifier masks.
    1.13       */
    1.14      public static final int
    1.15 @@ -365,7 +370,9 @@
    1.16          CLASH(Flags.CLASH),
    1.17          AUXILIARY(Flags.AUXILIARY),
    1.18          NOT_IN_PROFILE(Flags.NOT_IN_PROFILE),
    1.19 -        BAD_OVERRIDE(Flags.BAD_OVERRIDE);
    1.20 +        BAD_OVERRIDE(Flags.BAD_OVERRIDE),
    1.21 +        SIGNATURE_POLYMORPHIC(Flags.SIGNATURE_POLYMORPHIC),
    1.22 +        THROWS(Flags.THROWS);
    1.23  
    1.24          Flag(long flag) {
    1.25              this.value = flag;
     2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java	Fri Jul 12 13:11:12 2013 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java	Wed Jul 17 14:04:01 2013 +0100
     2.3 @@ -968,6 +968,39 @@
     2.4              }
     2.5          },
     2.6          /**
     2.7 +         * Infer uninstantiated/unbound inference variables occurring in 'throws'
     2.8 +         * clause as RuntimeException
     2.9 +         */
    2.10 +        THROWS(InferenceBound.UPPER) {
    2.11 +            @Override
    2.12 +            public boolean accepts(UndetVar t, InferenceContext inferenceContext) {
    2.13 +                if ((t.qtype.tsym.flags() & Flags.THROWS) == 0) {
    2.14 +                    //not a throws undet var
    2.15 +                    return false;
    2.16 +                }
    2.17 +                if (t.getBounds(InferenceBound.EQ, InferenceBound.LOWER, InferenceBound.UPPER)
    2.18 +                            .diff(t.getDeclaredBounds()).nonEmpty()) {
    2.19 +                    //not an unbounded undet var
    2.20 +                    return false;
    2.21 +                }
    2.22 +                Infer infer = inferenceContext.infer();
    2.23 +                for (Type db : t.getDeclaredBounds()) {
    2.24 +                    if (t.isInterface()) continue;
    2.25 +                    if (infer.types.asSuper(infer.syms.runtimeExceptionType, db.tsym) != null) {
    2.26 +                        //declared bound is a supertype of RuntimeException
    2.27 +                        return true;
    2.28 +                    }
    2.29 +                }
    2.30 +                //declared bound is more specific then RuntimeException - give up
    2.31 +                return false;
    2.32 +            }
    2.33 +
    2.34 +            @Override
    2.35 +            Type solve(UndetVar uv, InferenceContext inferenceContext) {
    2.36 +                return inferenceContext.infer().syms.runtimeExceptionType;
    2.37 +            }
    2.38 +        },
    2.39 +        /**
    2.40           * Instantiate an inference variables using its (ground) upper bounds. Such
    2.41           * bounds are merged together using glb().
    2.42           */
    2.43 @@ -1056,7 +1089,7 @@
    2.44  
    2.45          EQ(EnumSet.of(InferenceStep.EQ)),
    2.46          EQ_LOWER(EnumSet.of(InferenceStep.EQ, InferenceStep.LOWER)),
    2.47 -        EQ_LOWER_UPPER(EnumSet.of(InferenceStep.EQ, InferenceStep.LOWER, InferenceStep.UPPER));
    2.48 +        EQ_LOWER_THROWS_UPPER(EnumSet.of(InferenceStep.EQ, InferenceStep.LOWER, InferenceStep.THROWS, InferenceStep.UPPER));
    2.49  
    2.50          final EnumSet<InferenceStep> steps;
    2.51  
     3.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Fri Jul 12 13:11:12 2013 -0700
     3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java	Wed Jul 17 14:04:01 2013 +0100
     3.3 @@ -358,7 +358,8 @@
     3.4       *  @param thrown      The method's thrown exceptions.
     3.5       *  @param env             The method's (local) environment.
     3.6       */
     3.7 -    Type signature(List<JCTypeParameter> typarams,
     3.8 +    Type signature(MethodSymbol msym,
     3.9 +                   List<JCTypeParameter> typarams,
    3.10                     List<JCVariableDecl> params,
    3.11                     JCTree res,
    3.12                     JCVariableDecl recvparam,
    3.13 @@ -392,8 +393,12 @@
    3.14          ListBuffer<Type> thrownbuf = new ListBuffer<Type>();
    3.15          for (List<JCExpression> l = thrown; l.nonEmpty(); l = l.tail) {
    3.16              Type exc = attr.attribType(l.head, env);
    3.17 -            if (!exc.hasTag(TYPEVAR))
    3.18 +            if (!exc.hasTag(TYPEVAR)) {
    3.19                  exc = chk.checkClassType(l.head.pos(), exc);
    3.20 +            } else if (exc.tsym.owner == msym) {
    3.21 +                //mark inference variables in 'throws' clause
    3.22 +                exc.tsym.flags_field |= THROWS;
    3.23 +            }
    3.24              thrownbuf.append(exc);
    3.25          }
    3.26          MethodType mtype = new MethodType(argbuf.toList(),
    3.27 @@ -557,7 +562,7 @@
    3.28                  chk.setDeferredLintHandler(deferredLintHandler.setPos(tree.pos()));
    3.29          try {
    3.30              // Compute the method type
    3.31 -            m.type = signature(tree.typarams, tree.params,
    3.32 +            m.type = signature(m, tree.typarams, tree.params,
    3.33                                 tree.restype, tree.recvparam,
    3.34                                 tree.thrown,
    3.35                                 localEnv);
     4.1 --- a/test/tools/javac/generics/6723444/T6723444.java	Fri Jul 12 13:11:12 2013 -0700
     4.2 +++ b/test/tools/javac/generics/6723444/T6723444.java	Wed Jul 17 14:04:01 2013 +0100
     4.3 @@ -4,7 +4,8 @@
     4.4   *
     4.5   * @summary javac fails to substitute type variables into a constructor's throws clause
     4.6   * @author Mark Mahieu
     4.7 - * @compile/fail/ref=T6723444.out -XDrawDiagnostics T6723444.java
     4.8 + * @compile/fail/ref=T6723444_1.out -Xlint:-options -source 7 -XDrawDiagnostics T6723444.java
     4.9 + * @compile/fail/ref=T6723444_2.out -XDrawDiagnostics T6723444.java
    4.10   *
    4.11   */
    4.12  public class T6723444 {
     5.1 --- a/test/tools/javac/generics/6723444/T6723444.out	Fri Jul 12 13:11:12 2013 -0700
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,13 +0,0 @@
     5.4 -T6723444.java:42:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     5.5 -T6723444.java:43:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     5.6 -T6723444.java:45:32: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     5.7 -T6723444.java:46:17: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     5.8 -T6723444.java:48:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     5.9 -T6723444.java:49:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    5.10 -T6723444.java:50:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    5.11 -T6723444.java:51:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    5.12 -T6723444.java:52:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    5.13 -T6723444.java:53:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    5.14 -T6723444.java:54:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    5.15 -T6723444.java:55:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    5.16 -12 errors
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/tools/javac/generics/6723444/T6723444_1.out	Wed Jul 17 14:04:01 2013 +0100
     6.3 @@ -0,0 +1,13 @@
     6.4 +T6723444.java:43:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     6.5 +T6723444.java:44:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     6.6 +T6723444.java:46:32: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     6.7 +T6723444.java:47:17: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     6.8 +T6723444.java:49:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     6.9 +T6723444.java:50:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    6.10 +T6723444.java:51:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    6.11 +T6723444.java:52:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    6.12 +T6723444.java:53:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    6.13 +T6723444.java:54:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    6.14 +T6723444.java:55:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    6.15 +T6723444.java:56:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    6.16 +12 errors
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/tools/javac/generics/6723444/T6723444_2.out	Wed Jul 17 14:04:01 2013 +0100
     7.3 @@ -0,0 +1,11 @@
     7.4 +T6723444.java:46:32: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     7.5 +T6723444.java:47:17: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     7.6 +T6723444.java:49:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     7.7 +T6723444.java:50:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     7.8 +T6723444.java:51:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
     7.9 +T6723444.java:52:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    7.10 +T6723444.java:53:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    7.11 +T6723444.java:54:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    7.12 +T6723444.java:55:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    7.13 +T6723444.java:56:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Throwable
    7.14 +10 errors
     8.1 --- a/test/tools/javac/generics/7015430/T7015430.java	Fri Jul 12 13:11:12 2013 -0700
     8.2 +++ b/test/tools/javac/generics/7015430/T7015430.java	Wed Jul 17 14:04:01 2013 +0100
     8.3 @@ -4,7 +4,8 @@
     8.4   *
     8.5   * @summary  Incorrect thrown type determined for unchecked invocations
     8.6   * @author Daniel Smith
     8.7 - * @compile/fail/ref=T7015430.out -Xlint:unchecked -XDrawDiagnostics T7015430.java
     8.8 + * @compile/fail/ref=T7015430_1.out -source 7 -Xlint:-options,unchecked -XDrawDiagnostics T7015430.java
     8.9 + * @compile/fail/ref=T7015430_2.out -Xlint:unchecked -XDrawDiagnostics T7015430.java
    8.10   *
    8.11   */
    8.12  
     9.1 --- a/test/tools/javac/generics/7015430/T7015430.out	Fri Jul 12 13:11:12 2013 -0700
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,19 +0,0 @@
     9.4 -T7015430.java:41:14: compiler.warn.unchecked.meth.invocation.applied: kindname.method, empty, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
     9.5 -T7015430.java:41:15: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.Exception>
     9.6 -T7015430.java:50:41: compiler.warn.unchecked.meth.invocation.applied: kindname.method, empty, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
     9.7 -T7015430.java:50:42: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
     9.8 -T7015430.java:68:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
     9.9 -T7015430.java:68:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.Exception>
    9.10 -T7015430.java:77:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
    9.11 -T7015430.java:77:40: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
    9.12 -T7015430.java:104:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
    9.13 -T7015430.java:104:41: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
    9.14 -T7015430.java:113:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
    9.15 -T7015430.java:113:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.Exception>
    9.16 -T7015430.java:41:14: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
    9.17 -T7015430.java:68:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
    9.18 -T7015430.java:95:15: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
    9.19 -T7015430.java:113:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
    9.20 -T7015430.java:129:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
    9.21 -5 errors
    9.22 -12 warnings
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/tools/javac/generics/7015430/T7015430_1.out	Wed Jul 17 14:04:01 2013 +0100
    10.3 @@ -0,0 +1,19 @@
    10.4 +T7015430.java:42:14: compiler.warn.unchecked.meth.invocation.applied: kindname.method, empty, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
    10.5 +T7015430.java:42:15: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<E>
    10.6 +T7015430.java:51:41: compiler.warn.unchecked.meth.invocation.applied: kindname.method, empty, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
    10.7 +T7015430.java:51:42: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
    10.8 +T7015430.java:69:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
    10.9 +T7015430.java:69:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<E>
   10.10 +T7015430.java:78:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
   10.11 +T7015430.java:78:40: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
   10.12 +T7015430.java:105:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
   10.13 +T7015430.java:105:41: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
   10.14 +T7015430.java:114:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
   10.15 +T7015430.java:114:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<E>
   10.16 +T7015430.java:42:14: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
   10.17 +T7015430.java:69:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
   10.18 +T7015430.java:96:15: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
   10.19 +T7015430.java:114:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
   10.20 +T7015430.java:130:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
   10.21 +5 errors
   10.22 +12 warnings
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/tools/javac/generics/7015430/T7015430_2.out	Wed Jul 17 14:04:01 2013 +0100
    11.3 @@ -0,0 +1,15 @@
    11.4 +T7015430.java:42:14: compiler.warn.unchecked.meth.invocation.applied: kindname.method, empty, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
    11.5 +T7015430.java:42:15: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
    11.6 +T7015430.java:51:41: compiler.warn.unchecked.meth.invocation.applied: kindname.method, empty, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
    11.7 +T7015430.java:51:42: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
    11.8 +T7015430.java:69:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
    11.9 +T7015430.java:69:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
   11.10 +T7015430.java:78:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
   11.11 +T7015430.java:78:40: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
   11.12 +T7015430.java:105:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
   11.13 +T7015430.java:105:41: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
   11.14 +T7015430.java:114:9: compiler.warn.unchecked.meth.invocation.applied: kindname.constructor, <init>, java.lang.Iterable<E>, java.lang.Iterable, kindname.class, T7015430
   11.15 +T7015430.java:114:22: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.lang.Iterable, java.lang.Iterable<java.lang.RuntimeException>
   11.16 +T7015430.java:130:9: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
   11.17 +1 error
   11.18 +12 warnings
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/test/tools/javac/lambda/TargetType63.java	Wed Jul 17 14:04:01 2013 +0100
    12.3 @@ -0,0 +1,40 @@
    12.4 +/*
    12.5 + * @test /nodynamiccopyright/
    12.6 + * @summary smoke test for inference of throws type variables
    12.7 + * @compile/fail/ref=TargetType63.out -XDrawDiagnostics TargetType63.java
    12.8 + */
    12.9 +class TargetType63 {
   12.10 +
   12.11 +    interface F<T extends Throwable> {
   12.12 +        void m() throws T;
   12.13 +    }
   12.14 +
   12.15 +    void g1() { }
   12.16 +    void g2() throws ClassNotFoundException { }
   12.17 +    void g3() throws Exception { }
   12.18 +
   12.19 +    <Z extends Throwable> void m1(F<Z> fz) throws Z { }
   12.20 +    <Z extends ClassNotFoundException> void m2(F<Z> fz) throws Z { }
   12.21 +
   12.22 +    void test1() {
   12.23 +        m1(()->{ }); //ok (Z = RuntimeException)
   12.24 +        m1(this::g1); //ok (Z = RuntimeException)
   12.25 +    }
   12.26 +
   12.27 +    void test2() {
   12.28 +        m2(()->{ }); //fail (Z = ClassNotFoundException)
   12.29 +        m2(this::g1); //fail (Z = ClassNotFoundException)
   12.30 +    }
   12.31 +
   12.32 +    void test3() {
   12.33 +        m1(()->{ throw new ClassNotFoundException(); }); //fail (Z = ClassNotFoundException)
   12.34 +        m1(this::g2); //fail (Z = ClassNotFoundException)
   12.35 +        m2(()->{ throw new ClassNotFoundException(); }); //fail (Z = ClassNotFoundException)
   12.36 +        m2(this::g2); //fail (Z = ClassNotFoundException)
   12.37 +    }
   12.38 +
   12.39 +    void test4() {
   12.40 +        m1(()->{ throw new Exception(); }); //fail (Z = Exception)
   12.41 +        m1(this::g3); //fail (Z = Exception)
   12.42 +    }
   12.43 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/test/tools/javac/lambda/TargetType63.out	Wed Jul 17 14:04:01 2013 +0100
    13.3 @@ -0,0 +1,9 @@
    13.4 +TargetType63.java:25:11: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.ClassNotFoundException
    13.5 +TargetType63.java:26:11: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.ClassNotFoundException
    13.6 +TargetType63.java:30:11: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.ClassNotFoundException
    13.7 +TargetType63.java:31:11: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.ClassNotFoundException
    13.8 +TargetType63.java:32:11: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.ClassNotFoundException
    13.9 +TargetType63.java:33:11: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.ClassNotFoundException
   13.10 +TargetType63.java:37:11: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
   13.11 +TargetType63.java:38:11: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
   13.12 +8 errors

mercurial