Merge jdk7-b94

Wed, 19 May 2010 12:28:31 -0700

author
lana
date
Wed, 19 May 2010 12:28:31 -0700
changeset 552
bb3d7c75a56d
parent 546
e224d437e84a
parent 551
1cb2b5acc291
child 553
67cac01ed62a
child 554
9d9f26857129

Merge

     1.1 --- a/src/share/bin/launcher.sh-template	Thu May 13 13:22:31 2010 -0700
     1.2 +++ b/src/share/bin/launcher.sh-template	Wed May 19 12:28:31 2010 -0700
     1.3 @@ -66,4 +66,5 @@
     1.4  done
     1.5  unset DUALCASE
     1.6  
     1.7 -eval "#TARGET_JAVA#" "${bcp:+-Xbootclasspath/p:"$bcp"}" ${ea} ${javaOpts} -jar "${mydir}"/../lib/#PROGRAM#.jar ${toolOpts}
     1.8 +IFS=$nl
     1.9 +"#TARGET_JAVA#" "${bcp:+-Xbootclasspath/p:"$bcp"}" ${ea} ${javaOpts} -jar "${mydir}"/../lib/#PROGRAM#.jar ${toolOpts}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/share/classes/com/sun/source/tree/DisjointTypeTree.java	Wed May 19 12:28:31 2010 -0700
     2.3 @@ -0,0 +1,40 @@
     2.4 +/*
     2.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.  Sun designates this
    2.11 + * particular file as subject to the "Classpath" exception as provided
    2.12 + * by Sun in the LICENSE file that accompanied this code.
    2.13 + *
    2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.17 + * version 2 for more details (a copy is included in the LICENSE file that
    2.18 + * accompanied this code).
    2.19 + *
    2.20 + * You should have received a copy of the GNU General Public License version
    2.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.23 + *
    2.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    2.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    2.26 + * have any questions.
    2.27 + */
    2.28 +
    2.29 +package com.sun.source.tree;
    2.30 +
    2.31 +import java.util.List;
    2.32 +
    2.33 +/**
    2.34 + * A tree node for a disjoint type expression in a multicatch var declaration.
    2.35 + *
    2.36 + *
    2.37 + * @author Maurizio Cimadamore
    2.38 + *
    2.39 + * @since 1.7
    2.40 + */
    2.41 +public interface DisjointTypeTree extends Tree {
    2.42 +    List<? extends Tree> getTypeComponents();
    2.43 +}
    2.44 \ No newline at end of file
     3.1 --- a/src/share/classes/com/sun/source/tree/Tree.java	Thu May 13 13:22:31 2010 -0700
     3.2 +++ b/src/share/classes/com/sun/source/tree/Tree.java	Wed May 19 12:28:31 2010 -0700
     3.3 @@ -234,6 +234,11 @@
     3.4          PARAMETERIZED_TYPE(ParameterizedTypeTree.class),
     3.5  
     3.6          /**
     3.7 +         * Used for instances of {@link DisjointTypeTree}.
     3.8 +         */
     3.9 +        DISJOINT_TYPE(DisjointTypeTree.class),
    3.10 +
    3.11 +        /**
    3.12           * Used for instances of {@link TypeCastTree}.
    3.13           */
    3.14          TYPE_CAST(TypeCastTree.class),
     4.1 --- a/src/share/classes/com/sun/source/tree/TreeVisitor.java	Thu May 13 13:22:31 2010 -0700
     4.2 +++ b/src/share/classes/com/sun/source/tree/TreeVisitor.java	Wed May 19 12:28:31 2010 -0700
     4.3 @@ -96,6 +96,7 @@
     4.4      R visitCompilationUnit(CompilationUnitTree node, P p);
     4.5      R visitTry(TryTree node, P p);
     4.6      R visitParameterizedType(ParameterizedTypeTree node, P p);
     4.7 +    R visitDisjointType(DisjointTypeTree node, P p);
     4.8      R visitArrayType(ArrayTypeTree node, P p);
     4.9      R visitTypeCast(TypeCastTree node, P p);
    4.10      R visitPrimitiveType(PrimitiveTypeTree node, P p);
     5.1 --- a/src/share/classes/com/sun/source/util/SimpleTreeVisitor.java	Thu May 13 13:22:31 2010 -0700
     5.2 +++ b/src/share/classes/com/sun/source/util/SimpleTreeVisitor.java	Wed May 19 12:28:31 2010 -0700
     5.3 @@ -228,6 +228,10 @@
     5.4          return defaultAction(node, p);
     5.5      }
     5.6  
     5.7 +    public R visitDisjointType(DisjointTypeTree node, P p) {
     5.8 +        return defaultAction(node, p);
     5.9 +    }
    5.10 +
    5.11      public R visitTypeParameter(TypeParameterTree node, P p) {
    5.12          return defaultAction(node, p);
    5.13      }
     6.1 --- a/src/share/classes/com/sun/source/util/TreeScanner.java	Thu May 13 13:22:31 2010 -0700
     6.2 +++ b/src/share/classes/com/sun/source/util/TreeScanner.java	Wed May 19 12:28:31 2010 -0700
     6.3 @@ -354,6 +354,10 @@
     6.4          return r;
     6.5      }
     6.6  
     6.7 +    public R visitDisjointType(DisjointTypeTree node, P p) {
     6.8 +        return scan(node.getTypeComponents(), p);
     6.9 +    }
    6.10 +
    6.11      public R visitTypeParameter(TypeParameterTree node, P p) {
    6.12          R r = scan(node.getAnnotations(), p);
    6.13          r = scanAndReduce(node.getBounds(), p, r);
     7.1 --- a/src/share/classes/com/sun/tools/javac/code/Flags.java	Thu May 13 13:22:31 2010 -0700
     7.2 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java	Wed May 19 12:28:31 2010 -0700
     7.3 @@ -230,6 +230,11 @@
     7.4       */
     7.5      public static final long PROPRIETARY = 1L<<38;
     7.6  
     7.7 +    /**
     7.8 +     * Flag that marks a disjoint var in a multi-catch clause
     7.9 +     */
    7.10 +    public static final long DISJOINT = 1L<<39;
    7.11 +
    7.12      /** Modifier masks.
    7.13       */
    7.14      public static final int
     8.1 --- a/src/share/classes/com/sun/tools/javac/code/Source.java	Thu May 13 13:22:31 2010 -0700
     8.2 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java	Wed May 19 12:28:31 2010 -0700
     8.3 @@ -125,6 +125,9 @@
     8.4      public boolean allowDiamond() {
     8.5          return compareTo(JDK1_7) >= 0;
     8.6      }
     8.7 +    public boolean allowMulticatch() {
     8.8 +        return compareTo(JDK1_7) >= 0;
     8.9 +    }
    8.10      public boolean allowEnums() {
    8.11          return compareTo(JDK1_5) >= 0;
    8.12      }
     9.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu May 13 13:22:31 2010 -0700
     9.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed May 19 12:28:31 2010 -0700
     9.3 @@ -988,6 +988,13 @@
     9.4              Env<AttrContext> catchEnv =
     9.5                  env.dup(c, env.info.dup(env.info.scope.dup()));
     9.6              Type ctype = attribStat(c.param, catchEnv);
     9.7 +            if (TreeInfo.isMultiCatch(c)) {
     9.8 +                //check that multi-catch parameter is marked as final
     9.9 +                if ((c.param.sym.flags() & FINAL) == 0) {
    9.10 +                    log.error(c.param.pos(), "multicatch.param.must.be.final", c.param.sym);
    9.11 +                }
    9.12 +                c.param.sym.flags_field = c.param.sym.flags() | DISJOINT;
    9.13 +            }
    9.14              if (c.param.type.tsym.kind == Kinds.VAR) {
    9.15                  c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER);
    9.16              }
    9.17 @@ -2621,12 +2628,10 @@
    9.18              }
    9.19              if (useVarargs) {
    9.20                  JCTree tree = env.tree;
    9.21 -                Type argtype = owntype.getParameterTypes().last();
    9.22 -                if (!types.isReifiable(argtype))
    9.23 -                    chk.warnUnchecked(env.tree.pos(),
    9.24 -                                      "unchecked.generic.array.creation",
    9.25 -                                      argtype);
    9.26 -                Type elemtype = types.elemtype(argtype);
    9.27 +                if (owntype.getReturnType().tag != FORALL || warned) {
    9.28 +                    chk.checkVararg(env.tree.pos(), owntype.getParameterTypes());
    9.29 +                }
    9.30 +                Type elemtype = types.elemtype(owntype.getParameterTypes().last());
    9.31                  switch (tree.getTag()) {
    9.32                  case JCTree.APPLY:
    9.33                      ((JCMethodInvocation) tree).varargsElement = elemtype;
    9.34 @@ -2737,6 +2742,11 @@
    9.35          result = check(tree, owntype, TYP, pkind, pt);
    9.36      }
    9.37  
    9.38 +    public void visitTypeDisjoint(JCTypeDisjoint tree) {
    9.39 +        List<Type> componentTypes = attribTypes(tree.components, env);
    9.40 +        tree.type = result = check(tree, types.lub(componentTypes), TYP, pkind, pt);
    9.41 +    }
    9.42 +
    9.43      public void visitTypeParameter(JCTypeParameter tree) {
    9.44          TypeVar a = (TypeVar)tree.type;
    9.45          Set<Type> boundSet = new HashSet<Type>();
    10.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu May 13 13:22:31 2010 -0700
    10.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Wed May 19 12:28:31 2010 -0700
    10.3 @@ -677,6 +677,19 @@
    10.4          }
    10.5      }
    10.6  
    10.7 +    /**
    10.8 +     * Check that vararg method call is sound
    10.9 +     * @param pos Position to be used for error reporting.
   10.10 +     * @param argtypes Actual arguments supplied to vararg method.
   10.11 +     */
   10.12 +    void checkVararg(DiagnosticPosition pos, List<Type> argtypes) {
   10.13 +        Type argtype = argtypes.last();
   10.14 +        if (!types.isReifiable(argtype))
   10.15 +            warnUnchecked(pos,
   10.16 +                              "unchecked.generic.array.creation",
   10.17 +                              argtype);
   10.18 +    }
   10.19 +
   10.20      /** Check that given modifiers are legal for given symbol and
   10.21       *  return modifiers together with any implicit modififiers for that symbol.
   10.22       *  Warning: we can't use flags() here since this method
    11.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java	Thu May 13 13:22:31 2010 -0700
    11.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java	Wed May 19 12:28:31 2010 -0700
    11.3 @@ -27,6 +27,8 @@
    11.4  
    11.5  package com.sun.tools.javac.comp;
    11.6  
    11.7 +import java.util.HashMap;
    11.8 +
    11.9  import com.sun.tools.javac.code.*;
   11.10  import com.sun.tools.javac.tree.*;
   11.11  import com.sun.tools.javac.util.*;
   11.12 @@ -184,6 +186,7 @@
   11.13      private final Check chk;
   11.14      private       TreeMaker make;
   11.15      private       Lint lint;
   11.16 +    private final boolean allowRethrowAnalysis;
   11.17  
   11.18      public static Flow instance(Context context) {
   11.19          Flow instance = context.get(flowKey);
   11.20 @@ -194,13 +197,14 @@
   11.21  
   11.22      protected Flow(Context context) {
   11.23          context.put(flowKey, this);
   11.24 -
   11.25          names = Names.instance(context);
   11.26          log = Log.instance(context);
   11.27          syms = Symtab.instance(context);
   11.28          types = Types.instance(context);
   11.29          chk = Check.instance(context);
   11.30          lint = Lint.instance(context);
   11.31 +        Source source = Source.instance(context);
   11.32 +        allowRethrowAnalysis = source.allowMulticatch();
   11.33      }
   11.34  
   11.35      /** A flag that indicates whether the last statement could
   11.36 @@ -216,6 +220,8 @@
   11.37       */
   11.38      Bits uninits;
   11.39  
   11.40 +    HashMap<Symbol, List<Type>> multicatchTypes;
   11.41 +
   11.42      /** The set of variables that are definitely unassigned everywhere
   11.43       *  in current try block. This variable is maintained lazily; it is
   11.44       *  updated only when something gets removed from uninits,
   11.45 @@ -355,8 +361,14 @@
   11.46          if (sym.adr >= firstadr && trackable(sym)) {
   11.47              if ((sym.flags() & FINAL) != 0) {
   11.48                  if ((sym.flags() & PARAMETER) != 0) {
   11.49 -                    log.error(pos, "final.parameter.may.not.be.assigned",
   11.50 +                    if ((sym.flags() & DISJOINT) != 0) { //multi-catch parameter
   11.51 +                        log.error(pos, "multicatch.parameter.may.not.be.assigned",
   11.52 +                                  sym);
   11.53 +                    }
   11.54 +                    else {
   11.55 +                        log.error(pos, "final.parameter.may.not.be.assigned",
   11.56                                sym);
   11.57 +                    }
   11.58                  } else if (!uninits.isMember(sym.adr)) {
   11.59                      log.error(pos,
   11.60                                loopPassTwo
   11.61 @@ -952,8 +964,14 @@
   11.62          List<Type> caughtPrev = caught;
   11.63          List<Type> thrownPrev = thrown;
   11.64          thrown = List.nil();
   11.65 -        for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail)
   11.66 -            caught = chk.incl(l.head.param.type, caught);
   11.67 +        for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
   11.68 +            List<JCExpression> subClauses = TreeInfo.isMultiCatch(l.head) ?
   11.69 +                    ((JCTypeDisjoint)l.head.param.vartype).components :
   11.70 +                    List.of(l.head.param.vartype);
   11.71 +            for (JCExpression ct : subClauses) {
   11.72 +                caught = chk.incl(ct.type, caught);
   11.73 +            }
   11.74 +        }
   11.75          Bits uninitsTryPrev = uninitsTry;
   11.76          ListBuffer<PendingExit> prevPendingExits = pendingExits;
   11.77          pendingExits = new ListBuffer<PendingExit>();
   11.78 @@ -973,27 +991,39 @@
   11.79          for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
   11.80              alive = true;
   11.81              JCVariableDecl param = l.head.param;
   11.82 -            Type exc = param.type;
   11.83 -            if (chk.subset(exc, caughtInTry)) {
   11.84 -                log.error(l.head.pos(),
   11.85 -                          "except.already.caught", exc);
   11.86 -            } else if (!chk.isUnchecked(l.head.pos(), exc) &&
   11.87 -                       exc.tsym != syms.throwableType.tsym &&
   11.88 -                       exc.tsym != syms.exceptionType.tsym &&
   11.89 -                       !chk.intersects(exc, thrownInTry)) {
   11.90 -                log.error(l.head.pos(),
   11.91 -                          "except.never.thrown.in.try", exc);
   11.92 +            List<JCExpression> subClauses = TreeInfo.isMultiCatch(l.head) ?
   11.93 +                    ((JCTypeDisjoint)l.head.param.vartype).components :
   11.94 +                    List.of(l.head.param.vartype);
   11.95 +            List<Type> ctypes = List.nil();
   11.96 +            List<Type> rethrownTypes = chk.diff(thrownInTry, caughtInTry);
   11.97 +            for (JCExpression ct : subClauses) {
   11.98 +                Type exc = ct.type;
   11.99 +                ctypes = ctypes.append(exc);
  11.100 +                if (types.isSameType(exc, syms.objectType))
  11.101 +                    continue;
  11.102 +                if (chk.subset(exc, caughtInTry)) {
  11.103 +                    log.error(l.head.pos(),
  11.104 +                              "except.already.caught", exc);
  11.105 +                } else if (!chk.isUnchecked(l.head.pos(), exc) &&
  11.106 +                           exc.tsym != syms.throwableType.tsym &&
  11.107 +                           exc.tsym != syms.exceptionType.tsym &&
  11.108 +                           !chk.intersects(exc, thrownInTry)) {
  11.109 +                    log.error(l.head.pos(),
  11.110 +                              "except.never.thrown.in.try", exc);
  11.111 +                }
  11.112 +                caughtInTry = chk.incl(exc, caughtInTry);
  11.113              }
  11.114 -            caughtInTry = chk.incl(exc, caughtInTry);
  11.115              inits = initsTry.dup();
  11.116              uninits = uninitsTry.dup();
  11.117              scan(param);
  11.118              inits.incl(param.sym.adr);
  11.119              uninits.excl(param.sym.adr);
  11.120 +            multicatchTypes.put(param.sym, chk.intersect(ctypes, rethrownTypes));
  11.121              scanStat(l.head.body);
  11.122              initsEnd.andSet(inits);
  11.123              uninitsEnd.andSet(uninits);
  11.124              nextadr = nextadrCatch;
  11.125 +            multicatchTypes.remove(param.sym);
  11.126              aliveEnd |= alive;
  11.127          }
  11.128          if (tree.finalizer != null) {
  11.129 @@ -1121,7 +1151,19 @@
  11.130  
  11.131      public void visitThrow(JCThrow tree) {
  11.132          scanExpr(tree.expr);
  11.133 -        markThrown(tree, tree.expr.type);
  11.134 +        Symbol sym = TreeInfo.symbol(tree.expr);
  11.135 +        if (sym != null &&
  11.136 +            sym.kind == VAR &&
  11.137 +            (sym.flags() & FINAL) != 0 &&
  11.138 +            multicatchTypes.get(sym) != null &&
  11.139 +            allowRethrowAnalysis) {
  11.140 +            for (Type t : multicatchTypes.get(sym)) {
  11.141 +                markThrown(tree, t);
  11.142 +            }
  11.143 +        }
  11.144 +        else {
  11.145 +            markThrown(tree, tree.expr.type);
  11.146 +        }
  11.147          markDead();
  11.148      }
  11.149  
  11.150 @@ -1308,6 +1350,7 @@
  11.151              firstadr = 0;
  11.152              nextadr = 0;
  11.153              pendingExits = new ListBuffer<PendingExit>();
  11.154 +            multicatchTypes = new HashMap<Symbol, List<Type>>();
  11.155              alive = true;
  11.156              this.thrown = this.caught = null;
  11.157              this.classDef = null;
    12.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java	Thu May 13 13:22:31 2010 -0700
    12.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java	Wed May 19 12:28:31 2010 -0700
    12.3 @@ -287,7 +287,8 @@
    12.4      /** Instantiate method type `mt' by finding instantiations of
    12.5       *  `tvars' so that method can be applied to `argtypes'.
    12.6       */
    12.7 -    public Type instantiateMethod(List<Type> tvars,
    12.8 +    public Type instantiateMethod(final Env<AttrContext> env,
    12.9 +                                  List<Type> tvars,
   12.10                                    MethodType mt,
   12.11                                    final List<Type> argtypes,
   12.12                                    final boolean allowBoxing,
   12.13 @@ -416,6 +417,9 @@
   12.14                      // check that inferred bounds conform to their bounds
   12.15                      checkWithinBounds(all_tvars,
   12.16                             types.subst(inferredTypes, tvars, inferred), warn);
   12.17 +                    if (useVarargs) {
   12.18 +                        chk.checkVararg(env.tree.pos(), formals);
   12.19 +                    }
   12.20                      return super.inst(inferred, types);
   12.21              }};
   12.22              return mt2;
    13.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu May 13 13:22:31 2010 -0700
    13.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Wed May 19 12:28:31 2010 -0700
    13.3 @@ -345,7 +345,8 @@
    13.4  
    13.5          if (instNeeded)
    13.6              return
    13.7 -            infer.instantiateMethod(tvars,
    13.8 +            infer.instantiateMethod(env,
    13.9 +                                    tvars,
   13.10                                      (MethodType)mt,
   13.11                                      argtypes,
   13.12                                      allowBoxing,
    14.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Thu May 13 13:22:31 2010 -0700
    14.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java	Wed May 19 12:28:31 2010 -0700
    14.3 @@ -1454,20 +1454,26 @@
    14.4                        int startpc, int endpc,
    14.5                        List<Integer> gaps) {
    14.6              if (startpc != endpc) {
    14.7 -                int catchType = makeRef(tree.pos(), tree.param.type);
    14.8 -                while (gaps.nonEmpty()) {
    14.9 -                    int end = gaps.head.intValue();
   14.10 -                    registerCatch(tree.pos(),
   14.11 -                                  startpc,  end, code.curPc(),
   14.12 -                                  catchType);
   14.13 -                    gaps = gaps.tail;
   14.14 -                    startpc = gaps.head.intValue();
   14.15 -                    gaps = gaps.tail;
   14.16 +                List<JCExpression> subClauses = TreeInfo.isMultiCatch(tree) ?
   14.17 +                    ((JCTypeDisjoint)tree.param.vartype).components :
   14.18 +                    List.of(tree.param.vartype);
   14.19 +                for (JCExpression subCatch : subClauses) {
   14.20 +                    int catchType = makeRef(tree.pos(), subCatch.type);
   14.21 +                    List<Integer> lGaps = gaps;
   14.22 +                    while (lGaps.nonEmpty()) {
   14.23 +                        int end = lGaps.head.intValue();
   14.24 +                        registerCatch(tree.pos(),
   14.25 +                                      startpc,  end, code.curPc(),
   14.26 +                                      catchType);
   14.27 +                        lGaps = lGaps.tail;
   14.28 +                        startpc = lGaps.head.intValue();
   14.29 +                        lGaps = lGaps.tail;
   14.30 +                    }
   14.31 +                    if (startpc < endpc)
   14.32 +                        registerCatch(tree.pos(),
   14.33 +                                      startpc, endpc, code.curPc(),
   14.34 +                                      catchType);
   14.35                  }
   14.36 -                if (startpc < endpc)
   14.37 -                    registerCatch(tree.pos(),
   14.38 -                                  startpc, endpc, code.curPc(),
   14.39 -                                  catchType);
   14.40                  VarSymbol exparam = tree.param.sym;
   14.41                  code.statBegin(tree.pos);
   14.42                  code.markStatBegin();
    15.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Thu May 13 13:22:31 2010 -0700
    15.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java	Wed May 19 12:28:31 2010 -0700
    15.3 @@ -132,6 +132,7 @@
    15.4          this.allowStaticImport = source.allowStaticImport();
    15.5          this.allowAnnotations = source.allowAnnotations();
    15.6          this.allowDiamond = source.allowDiamond();
    15.7 +        this.allowMulticatch = source.allowMulticatch();
    15.8          this.allowTypeAnnotations = source.allowTypeAnnotations();
    15.9          this.keepDocComments = keepDocComments;
   15.10          if (keepDocComments)
   15.11 @@ -153,6 +154,10 @@
   15.12       */
   15.13      boolean allowDiamond;
   15.14  
   15.15 +    /** Switch: Should multicatch clause be accepted?
   15.16 +     */
   15.17 +    boolean allowMulticatch;
   15.18 +
   15.19      /** Switch: Should varargs be recognized?
   15.20       */
   15.21      boolean allowVarargs;
   15.22 @@ -2011,14 +2016,28 @@
   15.23          int pos = S.pos();
   15.24          accept(CATCH);
   15.25          accept(LPAREN);
   15.26 -        JCVariableDecl formal =
   15.27 -            variableDeclaratorId(optFinal(Flags.PARAMETER),
   15.28 -                                 qualident());
   15.29 +        JCModifiers mods = optFinal(Flags.PARAMETER);
   15.30 +        List<JCExpression> catchTypes = catchTypes();
   15.31 +        JCExpression paramType = catchTypes.size() > 1 ?
   15.32 +                toP(F.at(catchTypes.head.getStartPosition()).TypeDisjoint(catchTypes)) :
   15.33 +                catchTypes.head;
   15.34 +        JCVariableDecl formal = variableDeclaratorId(mods, paramType);
   15.35          accept(RPAREN);
   15.36          JCBlock body = block();
   15.37          return F.at(pos).Catch(formal, body);
   15.38      }
   15.39  
   15.40 +    List<JCExpression> catchTypes() {
   15.41 +        ListBuffer<JCExpression> catchTypes = ListBuffer.lb();
   15.42 +        catchTypes.add(parseType());
   15.43 +        while (S.token() == BAR) {
   15.44 +            checkMulticatch();
   15.45 +            S.nextToken();
   15.46 +            catchTypes.add(qualident());
   15.47 +        }
   15.48 +        return catchTypes.toList();
   15.49 +    }
   15.50 +
   15.51      /** SwitchBlockStatementGroups = { SwitchBlockStatementGroup }
   15.52       *  SwitchBlockStatementGroup = SwitchLabel BlockStatements
   15.53       *  SwitchLabel = CASE ConstantExpression ":" | DEFAULT ":"
   15.54 @@ -3193,4 +3212,10 @@
   15.55              allowDiamond = true;
   15.56          }
   15.57      }
   15.58 +    void checkMulticatch() {
   15.59 +        if (!allowMulticatch) {
   15.60 +            log.error(S.pos(), "multicatch.not.supported.in.source", source.name);
   15.61 +            allowMulticatch = true;
   15.62 +            }
   15.63 +    }
   15.64  }
    16.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Thu May 13 13:22:31 2010 -0700
    16.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Wed May 19 12:28:31 2010 -0700
    16.3 @@ -172,6 +172,10 @@
    16.4  
    16.5  compiler.err.final.parameter.may.not.be.assigned=\
    16.6      final parameter {0} may not be assigned
    16.7 +compiler.err.multicatch.parameter.may.not.be.assigned=\
    16.8 +    multi-catch parameter {0} may not be assigned
    16.9 +compiler.err.multicatch.param.must.be.final=\
   16.10 +    multi-catch parameter {0} must be final
   16.11  compiler.err.finally.without.try=\
   16.12      ''finally'' without ''try''
   16.13  compiler.err.foreach.not.applicable.to.type=\
   16.14 @@ -1235,6 +1239,10 @@
   16.15      enums are not supported in -source {0}\n\
   16.16  (use -source 5 or higher to enable enums)
   16.17  
   16.18 +compiler.err.multicatch.not.supported.in.source=\
   16.19 +    multi-catch statement is not supported in -source {0}\n\
   16.20 +(use -source 7 or higher to enable multi-catch statement)
   16.21 +
   16.22  compiler.err.string.switch.not.supported.in.source=\
   16.23      strings in switch are not supported in -source {0}\n\
   16.24  (use -source 7 or higher to enable strings in switch)
    17.1 --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java	Thu May 13 13:22:31 2010 -0700
    17.2 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java	Wed May 19 12:28:31 2010 -0700
    17.3 @@ -236,9 +236,13 @@
    17.4       */
    17.5      public static final int TYPEAPPLY = TYPEARRAY + 1;
    17.6  
    17.7 +    /** Disjunctive types, of type TypeDisjoint.
    17.8 +     */
    17.9 +    public static final int TYPEDISJOINT = TYPEAPPLY + 1;
   17.10 +
   17.11      /** Formal type parameters, of type TypeParameter.
   17.12       */
   17.13 -    public static final int TYPEPARAMETER = TYPEAPPLY + 1;
   17.14 +    public static final int TYPEPARAMETER = TYPEDISJOINT + 1;
   17.15  
   17.16      /** Type argument.
   17.17       */
   17.18 @@ -1863,6 +1867,34 @@
   17.19      }
   17.20  
   17.21      /**
   17.22 +     * A disjoint type, T1 | T2 | ... Tn (used in multicatch statements)
   17.23 +     */
   17.24 +    public static class JCTypeDisjoint extends JCExpression implements DisjointTypeTree {
   17.25 +
   17.26 +        public List<JCExpression> components;
   17.27 +
   17.28 +        protected JCTypeDisjoint(List<JCExpression> components) {
   17.29 +            this.components = components;
   17.30 +        }
   17.31 +        @Override
   17.32 +        public void accept(Visitor v) { v.visitTypeDisjoint(this); }
   17.33 +
   17.34 +        public Kind getKind() { return Kind.DISJOINT_TYPE; }
   17.35 +
   17.36 +        public List<JCExpression> getTypeComponents() {
   17.37 +            return components;
   17.38 +        }
   17.39 +        @Override
   17.40 +        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   17.41 +            return v.visitDisjointType(this, d);
   17.42 +        }
   17.43 +        @Override
   17.44 +        public int getTag() {
   17.45 +            return TYPEDISJOINT;
   17.46 +        }
   17.47 +    }
   17.48 +
   17.49 +    /**
   17.50       * A formal class parameter.
   17.51       * @param name name
   17.52       * @param bounds bounds
   17.53 @@ -2220,6 +2252,7 @@
   17.54          public void visitTypeIdent(JCPrimitiveTypeTree that) { visitTree(that); }
   17.55          public void visitTypeArray(JCArrayTypeTree that)     { visitTree(that); }
   17.56          public void visitTypeApply(JCTypeApply that)         { visitTree(that); }
   17.57 +        public void visitTypeDisjoint(JCTypeDisjoint that)   { visitTree(that); }
   17.58          public void visitTypeParameter(JCTypeParameter that) { visitTree(that); }
   17.59          public void visitWildcard(JCWildcard that)           { visitTree(that); }
   17.60          public void visitTypeBoundKind(TypeBoundKind that)   { visitTree(that); }
    18.1 --- a/src/share/classes/com/sun/tools/javac/tree/Pretty.java	Thu May 13 13:22:31 2010 -0700
    18.2 +++ b/src/share/classes/com/sun/tools/javac/tree/Pretty.java	Wed May 19 12:28:31 2010 -0700
    18.3 @@ -1182,6 +1182,14 @@
    18.4          }
    18.5      }
    18.6  
    18.7 +    public void visitTypeDisjoint(JCTypeDisjoint tree) {
    18.8 +        try {
    18.9 +            printExprs(tree.components, " | ");
   18.10 +        } catch (IOException e) {
   18.11 +            throw new UncheckedIOException(e);
   18.12 +        }
   18.13 +    }
   18.14 +
   18.15      public void visitTypeParameter(JCTypeParameter tree) {
   18.16          try {
   18.17              print(tree.name);
    19.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java	Thu May 13 13:22:31 2010 -0700
    19.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeCopier.java	Wed May 19 12:28:31 2010 -0700
    19.3 @@ -345,6 +345,12 @@
    19.4          return M.at(t.pos).TypeApply(clazz, arguments);
    19.5      }
    19.6  
    19.7 +    public JCTree visitDisjointType(DisjointTypeTree node, P p) {
    19.8 +        JCTypeDisjoint t = (JCTypeDisjoint) node;
    19.9 +        List<JCExpression> components = copy(t.components, p);
   19.10 +        return M.at(t.pos).TypeDisjoint(components);
   19.11 +    }
   19.12 +
   19.13      public JCTree visitArrayType(ArrayTypeTree node, P p) {
   19.14          JCArrayTypeTree t = (JCArrayTypeTree) node;
   19.15          JCExpression elemtype = copy(t.elemtype, p);
    20.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Thu May 13 13:22:31 2010 -0700
    20.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Wed May 19 12:28:31 2010 -0700
    20.3 @@ -118,6 +118,10 @@
    20.4          return false;
    20.5      }
    20.6  
    20.7 +    public static boolean isMultiCatch(JCCatch catchClause) {
    20.8 +        return catchClause.param.vartype.getTag() == JCTree.TYPEDISJOINT;
    20.9 +    }
   20.10 +
   20.11      /** Is statement an initializer for a synthetic field?
   20.12       */
   20.13      public static boolean isSyntheticInit(JCTree stat) {
    21.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Thu May 13 13:22:31 2010 -0700
    21.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Wed May 19 12:28:31 2010 -0700
    21.3 @@ -444,6 +444,12 @@
    21.4          return tree;
    21.5      }
    21.6  
    21.7 +    public JCTypeDisjoint TypeDisjoint(List<JCExpression> components) {
    21.8 +        JCTypeDisjoint tree = new JCTypeDisjoint(components);
    21.9 +        tree.pos = pos;
   21.10 +        return tree;
   21.11 +    }
   21.12 +
   21.13      public JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds) {
   21.14          return TypeParameter(name, bounds, List.<JCTypeAnnotation>nil());
   21.15      }
    22.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeScanner.java	Thu May 13 13:22:31 2010 -0700
    22.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeScanner.java	Wed May 19 12:28:31 2010 -0700
    22.3 @@ -275,6 +275,10 @@
    22.4          scan(tree.arguments);
    22.5      }
    22.6  
    22.7 +    public void visitTypeDisjoint(JCTypeDisjoint tree) {
    22.8 +        scan(tree.components);
    22.9 +    }
   22.10 +
   22.11      public void visitTypeParameter(JCTypeParameter tree) {
   22.12          scan(tree.annotations);
   22.13          scan(tree.bounds);
    23.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeTranslator.java	Thu May 13 13:22:31 2010 -0700
    23.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeTranslator.java	Wed May 19 12:28:31 2010 -0700
    23.3 @@ -367,6 +367,11 @@
    23.4          result = tree;
    23.5      }
    23.6  
    23.7 +    public void visitTypeDisjoint(JCTypeDisjoint tree) {
    23.8 +        tree.components = translate(tree.components);
    23.9 +        result = tree;
   23.10 +    }
   23.11 +
   23.12      public void visitTypeParameter(JCTypeParameter tree) {
   23.13          tree.annotations = translate(tree.annotations);
   23.14          tree.bounds = translate(tree.bounds);
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/test/tools/javac/multicatch/Neg01.java	Wed May 19 12:28:31 2010 -0700
    24.3 @@ -0,0 +1,28 @@
    24.4 +/*
    24.5 + * @test /nodynamiccopyright/
    24.6 + * @bug 6943289
    24.7 + *
    24.8 + * @summary Project Coin: Improved Exception Handling for Java (aka 'multicatch')
    24.9 + * @author darcy
   24.10 + * @compile/fail/ref=Neg01.out -XDrawDiagnostics Neg01.java
   24.11 + * @compile -source 6 -XDrawDiagnostics Neg01.java
   24.12 + *
   24.13 + */
   24.14 +
   24.15 +class Neg01 {
   24.16 +    static class A extends Exception {}
   24.17 +    static class B1 extends A {}
   24.18 +    static class B2 extends A {}
   24.19 +
   24.20 +    class Test {
   24.21 +        void m() throws A {
   24.22 +            try {
   24.23 +                throw new B1();
   24.24 +            } catch (final A ex1) {
   24.25 +                try {
   24.26 +                    throw ex1; // used to throw A, now throws B1!
   24.27 +                } catch (B2 ex2) { }//unreachable
   24.28 +            }
   24.29 +        }
   24.30 +    }
   24.31 +}
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/test/tools/javac/multicatch/Neg01.out	Wed May 19 12:28:31 2010 -0700
    25.3 @@ -0,0 +1,2 @@
    25.4 +Neg01.java:24:19: compiler.err.except.never.thrown.in.try: Neg01.B2
    25.5 +1 error
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/test/tools/javac/multicatch/Neg02.java	Wed May 19 12:28:31 2010 -0700
    26.3 @@ -0,0 +1,25 @@
    26.4 +/*
    26.5 + * @test /nodynamiccopyright/
    26.6 + * @bug 6943289
    26.7 + *
    26.8 + * @summary Project Coin: Improved Exception Handling for Java (aka 'multicatch')
    26.9 + * @author mcimadamore
   26.10 + * @compile/fail/ref=Neg02.out -XDrawDiagnostics Neg02.java
   26.11 + *
   26.12 + */
   26.13 +
   26.14 +class Neg02 {
   26.15 +    static class A extends Exception {}
   26.16 +    static class B extends Exception {}
   26.17 +
   26.18 +    void m() {
   26.19 +        try {
   26.20 +            if (true) {
   26.21 +                throw new A();
   26.22 +            }
   26.23 +            else {
   26.24 +                throw new B();
   26.25 +            }
   26.26 +        } catch (A | B ex) {  }
   26.27 +    }
   26.28 +}
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/test/tools/javac/multicatch/Neg02.out	Wed May 19 12:28:31 2010 -0700
    27.3 @@ -0,0 +1,2 @@
    27.4 +Neg02.java:23:24: compiler.err.multicatch.param.must.be.final: ex
    27.5 +1 error
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/test/tools/javac/multicatch/Neg03.java	Wed May 19 12:28:31 2010 -0700
    28.3 @@ -0,0 +1,27 @@
    28.4 +/*
    28.5 + * @test /nodynamiccopyright/
    28.6 + * @bug 6943289
    28.7 + *
    28.8 + * @summary Project Coin: Improved Exception Handling for Java (aka 'multicatch')
    28.9 + * @author mcimadamore
   28.10 + * @compile/fail/ref=Neg03.out -XDrawDiagnostics Neg03.java
   28.11 + *
   28.12 + */
   28.13 +
   28.14 +class Neg03 {
   28.15 +    static class A extends Exception {}
   28.16 +    static class B extends Exception {}
   28.17 +
   28.18 +    void m() {
   28.19 +        try {
   28.20 +            if (true) {
   28.21 +                throw new A();
   28.22 +            }
   28.23 +            else {
   28.24 +                throw new B();
   28.25 +            }
   28.26 +        } catch (final A | B ex) {
   28.27 +            ex = new B();
   28.28 +        }
   28.29 +    }
   28.30 +}
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/test/tools/javac/multicatch/Neg03.out	Wed May 19 12:28:31 2010 -0700
    29.3 @@ -0,0 +1,2 @@
    29.4 +Neg03.java:24:13: compiler.err.multicatch.parameter.may.not.be.assigned: ex
    29.5 +1 error
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/test/tools/javac/multicatch/Neg04.java	Wed May 19 12:28:31 2010 -0700
    30.3 @@ -0,0 +1,31 @@
    30.4 +/*
    30.5 + * @test /nodynamiccopyright/
    30.6 + * @bug 6943289
    30.7 + *
    30.8 + * @summary Project Coin: Improved Exception Handling for Java (aka 'multicatch')
    30.9 + * @author mcimadamore
   30.10 + * @compile/fail/ref=Neg04.out -XDrawDiagnostics Neg04.java
   30.11 + *
   30.12 + */
   30.13 +
   30.14 +class Neg04 {
   30.15 +    static class A extends Exception {}
   30.16 +    static class B extends Exception {}
   30.17 +
   30.18 +    void test() throws B {
   30.19 +        try {
   30.20 +            if (true) {
   30.21 +                throw new A();
   30.22 +            } else if (false) {
   30.23 +                throw new B();
   30.24 +            } else {
   30.25 +                throw (Throwable)new Exception();
   30.26 +            }
   30.27 +        }
   30.28 +        catch (A e) {}
   30.29 +        catch (final Exception e) {
   30.30 +            throw e;
   30.31 +        }
   30.32 +        catch (Throwable t) {}
   30.33 +    }
   30.34 +}
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/test/tools/javac/multicatch/Neg04.out	Wed May 19 12:28:31 2010 -0700
    31.3 @@ -0,0 +1,2 @@
    31.4 +Neg04.java:27:13: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception
    31.5 +1 error
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/test/tools/javac/multicatch/Pos01.java	Wed May 19 12:28:31 2010 -0700
    32.3 @@ -0,0 +1,59 @@
    32.4 +/*
    32.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    32.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    32.7 + *
    32.8 + * This code is free software; you can redistribute it and/or modify it
    32.9 + * under the terms of the GNU General Public License version 2 only, as
   32.10 + * published by the Free Software Foundation.
   32.11 + *
   32.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   32.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   32.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   32.15 + * version 2 for more details (a copy is included in the LICENSE file that
   32.16 + * accompanied this code).
   32.17 + *
   32.18 + * You should have received a copy of the GNU General Public License version
   32.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   32.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   32.21 + *
   32.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   32.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   32.24 + * have any questions.
   32.25 + */
   32.26 +
   32.27 +/*
   32.28 + * @test
   32.29 + * @bug 6943289
   32.30 + * @summary Project Coin: Improved Exception Handling for Java (aka 'multicatch')
   32.31 + *
   32.32 + */
   32.33 +
   32.34 +public class Pos01 {
   32.35 +
   32.36 +    static class A extends Exception {}
   32.37 +    static class B extends Exception {}
   32.38 +
   32.39 +    static int caughtExceptions = 0;
   32.40 +
   32.41 +    static void test(boolean b) {
   32.42 +        try {
   32.43 +            if (b) {
   32.44 +                throw new A();
   32.45 +            }
   32.46 +            else {
   32.47 +                throw new B();
   32.48 +            }
   32.49 +        }
   32.50 +        catch (final A | B ex) {
   32.51 +            caughtExceptions++;
   32.52 +        }
   32.53 +    }
   32.54 +
   32.55 +    public static void main(String[] args) {
   32.56 +        test(true);
   32.57 +        test(false);
   32.58 +        if (caughtExceptions != 2) {
   32.59 +            throw new AssertionError("Exception handler called " + caughtExceptions + "times");
   32.60 +        }
   32.61 +    }
   32.62 +}
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/test/tools/javac/multicatch/Pos02.java	Wed May 19 12:28:31 2010 -0700
    33.3 @@ -0,0 +1,81 @@
    33.4 +/*
    33.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    33.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    33.7 + *
    33.8 + * This code is free software; you can redistribute it and/or modify it
    33.9 + * under the terms of the GNU General Public License version 2 only, as
   33.10 + * published by the Free Software Foundation.
   33.11 + *
   33.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   33.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   33.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   33.15 + * version 2 for more details (a copy is included in the LICENSE file that
   33.16 + * accompanied this code).
   33.17 + *
   33.18 + * You should have received a copy of the GNU General Public License version
   33.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   33.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   33.21 + *
   33.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   33.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   33.24 + * have any questions.
   33.25 + */
   33.26 +
   33.27 +/*
   33.28 + * @test
   33.29 + * @bug 6943289
   33.30 + * @summary Project Coin: Improved Exception Handling for Java (aka 'multicatch')
   33.31 + *
   33.32 + */
   33.33 +
   33.34 +public class Pos02 {
   33.35 +
   33.36 +    static class A extends Exception {}
   33.37 +    static class B extends Exception {}
   33.38 +    static class C extends Exception {}
   33.39 +    static class C1 extends C {}
   33.40 +    static class C2 extends C {}
   33.41 +
   33.42 +    enum ExceptionKind {
   33.43 +        A,
   33.44 +        B,
   33.45 +        C1,
   33.46 +        C2
   33.47 +    }
   33.48 +
   33.49 +    static int caughtExceptions = 0;
   33.50 +    static int caughtRethrownExceptions = 0;
   33.51 +
   33.52 +    static void test(ExceptionKind ekind) throws A, C1 {
   33.53 +        try {
   33.54 +            switch (ekind) {
   33.55 +                case A : throw new A();
   33.56 +                case B : throw new B();
   33.57 +                case C1: throw new C1();
   33.58 +                case C2 : throw new C2();
   33.59 +            }
   33.60 +        }
   33.61 +        catch (final C2 | B ex) {
   33.62 +            caughtExceptions++;
   33.63 +        }
   33.64 +        catch (final C | A ex) {
   33.65 +            caughtExceptions++;
   33.66 +            throw ex;
   33.67 +        }
   33.68 +    }
   33.69 +
   33.70 +    public static void main(String[] args) {
   33.71 +        for (ExceptionKind ekind : ExceptionKind.values()) {
   33.72 +            try {
   33.73 +                test(ekind);
   33.74 +            }
   33.75 +            catch (final C1 | A ex) {
   33.76 +                caughtRethrownExceptions++;
   33.77 +            }
   33.78 +        }
   33.79 +        if (caughtExceptions != 4 && caughtRethrownExceptions == 2) {
   33.80 +            throw new AssertionError("Exception handler called " + caughtExceptions + "times" +
   33.81 +                                     " rethrown handler called " + caughtRethrownExceptions + "times");
   33.82 +        }
   33.83 +    }
   33.84 +}
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/test/tools/javac/multicatch/Pos03.java	Wed May 19 12:28:31 2010 -0700
    34.3 @@ -0,0 +1,50 @@
    34.4 +/*
    34.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    34.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    34.7 + *
    34.8 + * This code is free software; you can redistribute it and/or modify it
    34.9 + * under the terms of the GNU General Public License version 2 only, as
   34.10 + * published by the Free Software Foundation.
   34.11 + *
   34.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   34.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   34.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   34.15 + * version 2 for more details (a copy is included in the LICENSE file that
   34.16 + * accompanied this code).
   34.17 + *
   34.18 + * You should have received a copy of the GNU General Public License version
   34.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   34.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   34.21 + *
   34.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   34.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   34.24 + * have any questions.
   34.25 + */
   34.26 +
   34.27 +/*
   34.28 + * @test
   34.29 + * @bug 6943289
   34.30 + * @summary Project Coin: Improved Exception Handling for Java (aka 'multicatch')
   34.31 + * @compile Pos03.java
   34.32 + */
   34.33 +
   34.34 +class Pos03 {
   34.35 +
   34.36 +    static class A extends Exception { public void m() {}; public Object f;}
   34.37 +    static class B1 extends A {}
   34.38 +    static class B2 extends A {}
   34.39 +
   34.40 +    void m() {
   34.41 +        try {
   34.42 +            if (true) {
   34.43 +                throw new B1();
   34.44 +            }
   34.45 +            else {
   34.46 +                throw new B2();
   34.47 +            }
   34.48 +        } catch (final B1 | B2 ex) {
   34.49 +            ex.m();
   34.50 +            System.out.println(ex.f);
   34.51 +        }
   34.52 +    }
   34.53 +}
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/test/tools/javac/multicatch/Pos04.java	Wed May 19 12:28:31 2010 -0700
    35.3 @@ -0,0 +1,92 @@
    35.4 +/*
    35.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    35.7 + *
    35.8 + * This code is free software; you can redistribute it and/or modify it
    35.9 + * under the terms of the GNU General Public License version 2 only, as
   35.10 + * published by the Free Software Foundation.
   35.11 + *
   35.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   35.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   35.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   35.15 + * version 2 for more details (a copy is included in the LICENSE file that
   35.16 + * accompanied this code).
   35.17 + *
   35.18 + * You should have received a copy of the GNU General Public License version
   35.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   35.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   35.21 + *
   35.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   35.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   35.24 + * have any questions.
   35.25 + */
   35.26 +
   35.27 +/*
   35.28 + * @test
   35.29 + * @bug 6943289
   35.30 + * @summary Project Coin: Improved Exception Handling for Java (aka 'multicatch')
   35.31 + */
   35.32 +
   35.33 +import java.lang.annotation.*;
   35.34 +
   35.35 +public class Pos04 {
   35.36 +
   35.37 +    enum ExceptionKind {
   35.38 +        A(1),
   35.39 +        B(2),
   35.40 +        C(1);
   35.41 +
   35.42 +        int expectedValue;
   35.43 +
   35.44 +        ExceptionKind(int expectedValue) {
   35.45 +            this.expectedValue = expectedValue;
   35.46 +        }
   35.47 +    }
   35.48 +
   35.49 +    @Retention(RetentionPolicy.RUNTIME)
   35.50 +    @interface CatchNumber {
   35.51 +       int value();
   35.52 +    }
   35.53 +
   35.54 +    @CatchNumber(1)
   35.55 +    static class A extends Exception { }
   35.56 +
   35.57 +    @CatchNumber(2)
   35.58 +    static class B extends Exception { }
   35.59 +
   35.60 +    @CatchNumber(1)
   35.61 +    static class C extends Exception { }
   35.62 +
   35.63 +    static int sum = 0;
   35.64 +
   35.65 +    public static void main(String[] args) {
   35.66 +        for (ExceptionKind ekind : ExceptionKind.values()) {
   35.67 +            test(ekind);
   35.68 +        }
   35.69 +        if (sum != 4) {
   35.70 +            throw new Error("bad checksum - expected:4, found:" + sum);
   35.71 +        }
   35.72 +    }
   35.73 +
   35.74 +    public static void test(ExceptionKind ekind) {
   35.75 +        try {
   35.76 +            switch(ekind) {
   35.77 +                case A: throw new A();
   35.78 +                case B: throw new B();
   35.79 +                case C: throw new C();
   35.80 +            }
   35.81 +        } catch(final A | C ex) {// Catch number 1
   35.82 +            CatchNumber catchNumber = ex.getClass().getAnnotation(CatchNumber.class);
   35.83 +            if (catchNumber == null || catchNumber.value() != ekind.expectedValue) {
   35.84 +                throw new Error("was expecting 1 - got " + catchNumber);
   35.85 +            }
   35.86 +            sum += catchNumber.value();
   35.87 +        } catch (final B ex) { // Catch number 2
   35.88 +            CatchNumber catchNumber = ex.getClass().getAnnotation(CatchNumber.class);
   35.89 +            if (catchNumber == null || catchNumber.value() != ekind.expectedValue) {
   35.90 +                throw new Error("was expecting 2 - got " + catchNumber);
   35.91 +            }
   35.92 +            sum += catchNumber.value();
   35.93 +        }
   35.94 +    }
   35.95 +}
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/test/tools/javac/multicatch/Pos05.java	Wed May 19 12:28:31 2010 -0700
    36.3 @@ -0,0 +1,117 @@
    36.4 +/*
    36.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    36.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    36.7 + *
    36.8 + * This code is free software; you can redistribute it and/or modify it
    36.9 + * under the terms of the GNU General Public License version 2 only, as
   36.10 + * published by the Free Software Foundation.
   36.11 + *
   36.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   36.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   36.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   36.15 + * version 2 for more details (a copy is included in the LICENSE file that
   36.16 + * accompanied this code).
   36.17 + *
   36.18 + * You should have received a copy of the GNU General Public License version
   36.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   36.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   36.21 + *
   36.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   36.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   36.24 + * have any questions.
   36.25 + */
   36.26 +
   36.27 +/*
   36.28 + * @test
   36.29 + * @bug 6943289
   36.30 + * @summary  Project Coin: Improved Exception Handling for Java (aka 'multicatch')
   36.31 + * @run main Pos05
   36.32 + */
   36.33 +
   36.34 +import com.sun.tools.classfile.Attribute;
   36.35 +import com.sun.tools.classfile.ClassFile;
   36.36 +import com.sun.tools.classfile.Code_attribute;
   36.37 +import com.sun.tools.classfile.Code_attribute.Exception_data;
   36.38 +import com.sun.tools.classfile.Method;
   36.39 +import java.io.*;
   36.40 +
   36.41 +public class Pos05 {
   36.42 +
   36.43 +    static class Pos05sub {
   36.44 +
   36.45 +        class A extends Exception {}
   36.46 +        class B extends Exception {}
   36.47 +        class C extends Exception {}
   36.48 +
   36.49 +        void test(boolean b1, boolean b2) {
   36.50 +            try {
   36.51 +                if (b1) {
   36.52 +                    throw new A();
   36.53 +                }
   36.54 +                else if (b2) {
   36.55 +                    throw new B();
   36.56 +                }
   36.57 +                else {
   36.58 +                    throw new C();
   36.59 +                }
   36.60 +            }
   36.61 +            catch (final A | B | C ex) {
   36.62 +                System.out.println("Exception caught");
   36.63 +            }
   36.64 +        }
   36.65 +    }
   36.66 +
   36.67 +    static final int TYPES_IN_MULTICATCH = 3;
   36.68 +    static final String SUBTEST_NAME = Pos05sub.class.getName() + ".class";
   36.69 +    static final String TEST_METHOD_NAME = "test";
   36.70 +
   36.71 +    public static void main(String... args) throws Exception {
   36.72 +        new Pos05().run();
   36.73 +    }
   36.74 +
   36.75 +    public void run() throws Exception {
   36.76 +        String workDir = System.getProperty("test.classes");
   36.77 +        File compiledTest = new File(workDir, SUBTEST_NAME);
   36.78 +        verifyMulticatchExceptionRanges(compiledTest);
   36.79 +    }
   36.80 +
   36.81 +    void verifyMulticatchExceptionRanges(File f) {
   36.82 +        System.err.println("verify: " + f);
   36.83 +        try {
   36.84 +            int count = 0;
   36.85 +            ClassFile cf = ClassFile.read(f);
   36.86 +            Method testMethod = null;
   36.87 +            for (Method m : cf.methods) {
   36.88 +                if (m.getName(cf.constant_pool).equals(TEST_METHOD_NAME)) {
   36.89 +                    testMethod = m;
   36.90 +                    break;
   36.91 +                }
   36.92 +            }
   36.93 +            if (testMethod == null) {
   36.94 +                throw new Error("Test method not found");
   36.95 +            }
   36.96 +            Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
   36.97 +            if (testMethod == null) {
   36.98 +                throw new Error("Code attribute for test() method not found");
   36.99 +            }
  36.100 +            Exception_data firstExceptionTable = null;
  36.101 +            for (int i = 0 ; i < ea.exception_table_langth; i++) {
  36.102 +                if (firstExceptionTable == null) {
  36.103 +                    firstExceptionTable = ea.exception_table[i];
  36.104 +                }
  36.105 +                if (ea.exception_table[i].handler_pc != firstExceptionTable.handler_pc ||
  36.106 +                        ea.exception_table[i].start_pc != firstExceptionTable.start_pc ||
  36.107 +                        ea.exception_table[i].end_pc != firstExceptionTable.end_pc) {
  36.108 +                    throw new Error("Multiple overlapping catch clause found in generated code");
  36.109 +                }
  36.110 +                count++;
  36.111 +            }
  36.112 +            if (count != TYPES_IN_MULTICATCH) {
  36.113 +                throw new Error("Wrong number of exception data found: " + count);
  36.114 +            }
  36.115 +        } catch (Exception e) {
  36.116 +            e.printStackTrace();
  36.117 +            throw new Error("error reading " + f +": " + e);
  36.118 +        }
  36.119 +    }
  36.120 +}
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/test/tools/javac/varargs/6730476/T6730476a.java	Wed May 19 12:28:31 2010 -0700
    37.3 @@ -0,0 +1,39 @@
    37.4 +/*
    37.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    37.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    37.7 + *
    37.8 + * This code is free software; you can redistribute it and/or modify it
    37.9 + * under the terms of the GNU General Public License version 2 only, as
   37.10 + * published by the Free Software Foundation.
   37.11 + *
   37.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   37.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   37.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   37.15 + * version 2 for more details (a copy is included in the LICENSE file that
   37.16 + * accompanied this code).
   37.17 + *
   37.18 + * You should have received a copy of the GNU General Public License version
   37.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   37.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   37.21 + *
   37.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   37.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   37.24 + * have any questions.
   37.25 + */
   37.26 +
   37.27 +/*
   37.28 + * @test
   37.29 + * @bug 6730476
   37.30 + *
   37.31 + * @summary invalid "unchecked generic array" warning
   37.32 + * @author mcimadamore
   37.33 + * @compile T6730476a.java -Xlint -Werror
   37.34 + *
   37.35 + */
   37.36 +
   37.37 +class T6730476a {
   37.38 +    <T> void f(int i, T ... x) {}
   37.39 +    void g() {
   37.40 +      f(1);
   37.41 +    }
   37.42 +}
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/test/tools/javac/varargs/6730476/T6730476b.java	Wed May 19 12:28:31 2010 -0700
    38.3 @@ -0,0 +1,36 @@
    38.4 +/*
    38.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
    38.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    38.7 + *
    38.8 + * This code is free software; you can redistribute it and/or modify it
    38.9 + * under the terms of the GNU General Public License version 2 only, as
   38.10 + * published by the Free Software Foundation.
   38.11 + *
   38.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   38.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   38.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   38.15 + * version 2 for more details (a copy is included in the LICENSE file that
   38.16 + * accompanied this code).
   38.17 + *
   38.18 + * You should have received a copy of the GNU General Public License version
   38.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   38.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   38.21 + *
   38.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   38.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   38.24 + * have any questions.
   38.25 + */
   38.26 +
   38.27 +/*
   38.28 + * @test
   38.29 + * @bug 6730476
   38.30 + *
   38.31 + * @summary invalid "unchecked generic array" warning
   38.32 + * @author mcimadamore
   38.33 + * @compile T6730476b.java -Xlint -Werror
   38.34 + *
   38.35 + */
   38.36 +
   38.37 +class T6730476b {
   38.38 +    java.util.List<Integer> ints = java.util.Arrays.asList();
   38.39 +}

mercurial