langtools/test/tools/javac/TryWithResources/InterruptedExceptionTest.java
author ksrini
Thu, 01 Sep 2011 09:14:25 -0700
changeset 10455 3d070be0fff8
parent 9076 45c73da050e9
child 27319 030080f03e4f
permissions -rw-r--r--
7073631: (javac) javac parser improvements for error position reporting Summary: JavacParser improvements for NetBeans, improved by LangTools. Reviewed-by: mcimadamore, jjg Contributed-by: jan.lahoda@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9076
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
     1
/*
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
     4
 *
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
     8
 *
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    14
 *
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    18
 *
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    21
 * questions.
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    22
 */
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    23
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    24
/*
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    25
 * @test
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    26
 * @bug 7027157
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    27
 * @summary Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    28
 */
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    29
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    30
import com.sun.source.util.JavacTask;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    31
import java.net.URI;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    32
import java.util.Arrays;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    33
import javax.tools.Diagnostic;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    34
import javax.tools.JavaCompiler;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    35
import javax.tools.JavaFileObject;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    36
import javax.tools.SimpleJavaFileObject;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    37
import javax.tools.StandardJavaFileManager;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    38
import javax.tools.ToolProvider;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    39
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    40
public class InterruptedExceptionTest {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    41
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    42
    enum XlintOption {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    43
        NONE("none"),
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    44
        TRY("try");
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    45
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    46
        String opt;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    47
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    48
        XlintOption(String opt) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    49
            this.opt = opt;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    50
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    51
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    52
        String getXlintOption() {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    53
            return "-Xlint:" + opt;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    54
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    55
    }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    56
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    57
    enum SuppressLevel {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    58
        NONE,
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    59
        SUPPRESS;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    60
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    61
        String getSuppressAnno() {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    62
            return this == SUPPRESS ?
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    63
                "@SuppressWarnings(\"try\")" :
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    64
                "";
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    65
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    66
    }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    67
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    68
    enum ClassKind {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    69
        ABSTRACT_CLASS("abstract class", "implements", false),
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    70
        CLASS("class", "implements", true),
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    71
        INTERFACE("interface", "extends", false);
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    72
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    73
        String kindName;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    74
        String extendsClause;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    75
        boolean hasBody;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    76
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    77
        private ClassKind(String kindName, String extendsClause, boolean hasBody) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    78
            this.kindName = kindName;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    79
            this.extendsClause = extendsClause;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    80
            this.hasBody = hasBody;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    81
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    82
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    83
        String getBody() {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    84
            return hasBody ? "{}" : ";";
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    85
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    86
    }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    87
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    88
    enum ExceptionKind {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    89
        NONE("", false),
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    90
        EXCEPTION("Exception", true),
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    91
        INTERRUPTED_EXCEPTION("InterruptedException", true),
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    92
        ILLEGAL_ARGUMENT_EXCEPTION("IllegalArgumentException", false),
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    93
        X("X", false);
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    94
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    95
        String exName;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    96
        boolean shouldWarn;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    97
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    98
        private ExceptionKind(String exName, boolean shouldWarn) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    99
            this.exName = exName;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   100
            this.shouldWarn = shouldWarn;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   101
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   102
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   103
        String getThrowsClause() {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   104
            return this == NONE ? "" : "throws " + exName;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   105
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   106
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   107
        String getTypeArguments(ExceptionKind decl) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   108
            return (decl != X || this == NONE) ? "" : "<" + exName + ">";
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   109
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   110
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   111
        String getTypeParameter() {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   112
            return this == X ? "<X extends Exception>" : "";
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   113
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   114
    }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   115
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   116
    public static void main(String... args) throws Exception {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   117
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   118
        //create default shared JavaCompiler - reused across multiple compilations
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   119
        JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   120
        StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   121
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   122
        for (XlintOption xlint : XlintOption.values()) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   123
            for (SuppressLevel suppress_decl : SuppressLevel.values()) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   124
                for (SuppressLevel suppress_use : SuppressLevel.values()) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   125
                    for (ClassKind ck : ClassKind.values()) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   126
                        for (ExceptionKind ek_decl : ExceptionKind.values()) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   127
                            for (ExceptionKind ek_use : ExceptionKind.values()) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   128
                                new InterruptedExceptionTest(xlint, suppress_decl,
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   129
                                        suppress_use, ck, ek_decl, ek_use).run(comp, fm);
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   130
                            }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   131
                        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   132
                    }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   133
                }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   134
            }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   135
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   136
    }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   137
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   138
    XlintOption xlint;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   139
    SuppressLevel suppress_decl;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   140
    SuppressLevel suppress_use;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   141
    ClassKind ck;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   142
    ExceptionKind ek_decl;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   143
    ExceptionKind ek_use;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   144
    JavaSource source;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   145
    DiagnosticChecker diagChecker;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   146
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   147
    InterruptedExceptionTest(XlintOption xlint, SuppressLevel suppress_decl, SuppressLevel suppress_use,
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   148
            ClassKind ck, ExceptionKind ek_decl, ExceptionKind ek_use) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   149
        this.xlint = xlint;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   150
        this.suppress_decl = suppress_decl;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   151
        this.suppress_use = suppress_use;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   152
        this.ck = ck;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   153
        this.ek_decl = ek_decl;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   154
        this.ek_use = ek_use;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   155
        this.source = new JavaSource();
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   156
        this.diagChecker = new DiagnosticChecker();
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   157
    }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   158
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   159
    class JavaSource extends SimpleJavaFileObject {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   160
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   161
        String template = "#S1 #CK Resource#G #EC AutoCloseable {\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   162
                              "public void close() #TK #BK\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   163
                          "}\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   164
                          "class Test {\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   165
                              "#S2 <X> void test() {\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   166
                                 "try (Resource#PK r = null) { }\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   167
                              "}\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   168
                          "}\n";
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   169
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   170
        String source;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   171
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   172
        public JavaSource() {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   173
            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   174
            source = template.replace("#S1", suppress_decl.getSuppressAnno())
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   175
                    .replace("#S2", suppress_use.getSuppressAnno())
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   176
                    .replace("#CK", ck.kindName)
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   177
                    .replace("#EC", ck.extendsClause)
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   178
                    .replace("#G", ek_decl.getTypeParameter())
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   179
                    .replace("#TK", ek_decl.getThrowsClause())
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   180
                    .replace("#BK", ck.getBody())
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   181
                    .replace("#PK", ek_use.getTypeArguments(ek_decl));
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   182
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   183
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   184
        @Override
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   185
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   186
            return source;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   187
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   188
    }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   189
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   190
    void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   191
        JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   192
                Arrays.asList(xlint.getXlintOption()), null, Arrays.asList(source));
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   193
        ct.analyze();
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   194
        check();
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   195
    }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   196
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   197
    void check() {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   198
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   199
        boolean shouldWarnDecl = ek_decl.shouldWarn &&
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   200
                xlint == XlintOption.TRY &&
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   201
                suppress_decl != SuppressLevel.SUPPRESS;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   202
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   203
        boolean shouldWarnUse = (ek_decl.shouldWarn ||
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   204
                ((ek_use.shouldWarn || ek_use == ExceptionKind.NONE) && ek_decl == ExceptionKind.X)) &&
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   205
                xlint == XlintOption.TRY &&
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   206
                suppress_use != SuppressLevel.SUPPRESS;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   207
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   208
        int foundWarnings = 0;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   209
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   210
        if (shouldWarnDecl) foundWarnings++;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   211
        if (shouldWarnUse) foundWarnings++;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   212
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   213
        if (foundWarnings != diagChecker.tryWarnFound) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   214
            throw new Error("invalid diagnostics for source:\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   215
                source.getCharContent(true) +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   216
                "\nOptions: " + xlint.getXlintOption() +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   217
                "\nFound warnings: " + diagChecker.tryWarnFound +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   218
                "\nExpected decl warning: " + shouldWarnDecl +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   219
                "\nExpected use warning: " + shouldWarnUse);
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   220
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   221
    }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   222
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   223
    static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   224
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   225
        int tryWarnFound;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   226
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   227
        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   228
            if (diagnostic.getKind() == Diagnostic.Kind.WARNING &&
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   229
                    diagnostic.getCode().contains("try.resource.throws.interrupted.exc")) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   230
                tryWarnFound++;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   231
            }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   232
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   233
    }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   234
}