langtools/test/tools/javac/TryWithResources/InterruptedExceptionTest.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 27319 030080f03e4f
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
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
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
9076
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
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 27319
diff changeset
    28
 * @modules jdk.compiler
9076
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
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    31
import com.sun.source.util.JavacTask;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    32
import java.net.URI;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    33
import java.util.Arrays;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    34
import javax.tools.Diagnostic;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    35
import javax.tools.JavaCompiler;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    36
import javax.tools.JavaFileObject;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    37
import javax.tools.SimpleJavaFileObject;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    38
import javax.tools.StandardJavaFileManager;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    39
import javax.tools.ToolProvider;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    40
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    41
public class InterruptedExceptionTest {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    42
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    43
    enum XlintOption {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    44
        NONE("none"),
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    45
        TRY("try");
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    46
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    47
        String opt;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    48
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    49
        XlintOption(String opt) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    50
            this.opt = opt;
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
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    53
        String getXlintOption() {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    54
            return "-Xlint:" + opt;
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
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    58
    enum SuppressLevel {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    59
        NONE,
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    60
        SUPPRESS;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    61
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    62
        String getSuppressAnno() {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    63
            return this == SUPPRESS ?
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    64
                "@SuppressWarnings(\"try\")" :
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
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    69
    enum ClassKind {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    70
        ABSTRACT_CLASS("abstract class", "implements", false),
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    71
        CLASS("class", "implements", true),
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    72
        INTERFACE("interface", "extends", false);
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    73
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    74
        String kindName;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    75
        String extendsClause;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    76
        boolean hasBody;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    77
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    78
        private ClassKind(String kindName, String extendsClause, boolean hasBody) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    79
            this.kindName = kindName;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    80
            this.extendsClause = extendsClause;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    81
            this.hasBody = hasBody;
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
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    84
        String getBody() {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    85
            return hasBody ? "{}" : ";";
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
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    89
    enum ExceptionKind {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    90
        NONE("", false),
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    91
        EXCEPTION("Exception", true),
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    92
        INTERRUPTED_EXCEPTION("InterruptedException", true),
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    93
        ILLEGAL_ARGUMENT_EXCEPTION("IllegalArgumentException", false),
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    94
        X("X", false);
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    95
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    96
        String exName;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    97
        boolean shouldWarn;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    98
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
    99
        private ExceptionKind(String exName, boolean shouldWarn) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   100
            this.exName = exName;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   101
            this.shouldWarn = shouldWarn;
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
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   104
        String getThrowsClause() {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   105
            return this == NONE ? "" : "throws " + exName;
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
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   108
        String getTypeArguments(ExceptionKind decl) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   109
            return (decl != X || this == NONE) ? "" : "<" + exName + ">";
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
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   112
        String getTypeParameter() {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   113
            return this == X ? "<X extends Exception>" : "";
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
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   117
    public static void main(String... args) throws Exception {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   118
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   119
        //create default shared JavaCompiler - reused across multiple compilations
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   120
        JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9076
diff changeset
   121
        try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
9076
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   122
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9076
diff changeset
   123
            for (XlintOption xlint : XlintOption.values()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9076
diff changeset
   124
                for (SuppressLevel suppress_decl : SuppressLevel.values()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9076
diff changeset
   125
                    for (SuppressLevel suppress_use : SuppressLevel.values()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9076
diff changeset
   126
                        for (ClassKind ck : ClassKind.values()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9076
diff changeset
   127
                            for (ExceptionKind ek_decl : ExceptionKind.values()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9076
diff changeset
   128
                                for (ExceptionKind ek_use : ExceptionKind.values()) {
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9076
diff changeset
   129
                                    new InterruptedExceptionTest(xlint, suppress_decl,
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9076
diff changeset
   130
                                            suppress_use, ck, ek_decl, ek_use).run(comp, fm);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 9076
diff changeset
   131
                                }
9076
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
    }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   139
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   140
    XlintOption xlint;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   141
    SuppressLevel suppress_decl;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   142
    SuppressLevel suppress_use;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   143
    ClassKind ck;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   144
    ExceptionKind ek_decl;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   145
    ExceptionKind ek_use;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   146
    JavaSource source;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   147
    DiagnosticChecker diagChecker;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   148
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   149
    InterruptedExceptionTest(XlintOption xlint, SuppressLevel suppress_decl, SuppressLevel suppress_use,
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   150
            ClassKind ck, ExceptionKind ek_decl, ExceptionKind ek_use) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   151
        this.xlint = xlint;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   152
        this.suppress_decl = suppress_decl;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   153
        this.suppress_use = suppress_use;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   154
        this.ck = ck;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   155
        this.ek_decl = ek_decl;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   156
        this.ek_use = ek_use;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   157
        this.source = new JavaSource();
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   158
        this.diagChecker = new DiagnosticChecker();
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   159
    }
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
    class JavaSource extends SimpleJavaFileObject {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   162
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   163
        String template = "#S1 #CK Resource#G #EC AutoCloseable {\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   164
                              "public void close() #TK #BK\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   165
                          "}\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   166
                          "class Test {\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   167
                              "#S2 <X> void test() {\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   168
                                 "try (Resource#PK r = null) { }\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   169
                              "}\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   170
                          "}\n";
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
        String source;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   173
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   174
        public JavaSource() {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   175
            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   176
            source = template.replace("#S1", suppress_decl.getSuppressAnno())
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   177
                    .replace("#S2", suppress_use.getSuppressAnno())
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   178
                    .replace("#CK", ck.kindName)
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   179
                    .replace("#EC", ck.extendsClause)
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   180
                    .replace("#G", ek_decl.getTypeParameter())
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   181
                    .replace("#TK", ek_decl.getThrowsClause())
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   182
                    .replace("#BK", ck.getBody())
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   183
                    .replace("#PK", ek_use.getTypeArguments(ek_decl));
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   184
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   185
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   186
        @Override
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   187
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   188
            return source;
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
    }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   191
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   192
    void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   193
        JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   194
                Arrays.asList(xlint.getXlintOption()), null, Arrays.asList(source));
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   195
        ct.analyze();
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   196
        check();
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   197
    }
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
    void check() {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   200
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   201
        boolean shouldWarnDecl = ek_decl.shouldWarn &&
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   202
                xlint == XlintOption.TRY &&
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   203
                suppress_decl != SuppressLevel.SUPPRESS;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   204
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   205
        boolean shouldWarnUse = (ek_decl.shouldWarn ||
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   206
                ((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
   207
                xlint == XlintOption.TRY &&
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   208
                suppress_use != SuppressLevel.SUPPRESS;
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
        int foundWarnings = 0;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   211
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   212
        if (shouldWarnDecl) foundWarnings++;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   213
        if (shouldWarnUse) foundWarnings++;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   214
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   215
        if (foundWarnings != diagChecker.tryWarnFound) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   216
            throw new Error("invalid diagnostics for source:\n" +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   217
                source.getCharContent(true) +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   218
                "\nOptions: " + xlint.getXlintOption() +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   219
                "\nFound warnings: " + diagChecker.tryWarnFound +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   220
                "\nExpected decl warning: " + shouldWarnDecl +
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   221
                "\nExpected use warning: " + shouldWarnUse);
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
    }
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
    static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
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
        int tryWarnFound;
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   228
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   229
        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   230
            if (diagnostic.getKind() == Diagnostic.Kind.WARNING &&
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   231
                    diagnostic.getCode().contains("try.resource.throws.interrupted.exc")) {
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   232
                tryWarnFound++;
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
        }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   235
    }
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
diff changeset
   236
}