author | hseigel |
Wed, 02 Mar 2016 23:48:41 +0000 | |
changeset 36397 | c487ced7231c |
parent 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
10 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
2 |
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5520 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
10 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6397286 |
|
27 |
* @summary TaskListener calls are not protected agains user exceptions |
|
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
29 |
* jdk.compiler/com.sun.tools.javac.file |
10 | 30 |
*/ |
31 |
||
32 |
import java.io.*; |
|
33 |
import java.util.*; |
|
34 |
import javax.tools.*; |
|
35 |
import com.sun.source.util.*; |
|
36 |
import com.sun.tools.javac.api.*; |
|
37 |
||
38 |
public class T6397286 { |
|
39 |
||
40 |
public static void main(String[] args) throws IOException { |
|
41 |
String testSrcDir = System.getProperty("test.src"); |
|
42 |
String self = T6397286.class.getName(); |
|
43 |
||
44 |
JavacTool tool = JavacTool.create(); |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
45 |
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
46 |
Iterable<? extends JavaFileObject> files = |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
47 |
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java"))); |
10 | 48 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
49 |
JavacTask task = tool.getTask(null, fm, null, null, null, files); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
50 |
task.setTaskListener(new TaskListener() { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
51 |
public void started(TaskEvent e) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
52 |
throw new TaskEventError(e); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
53 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
54 |
public void finished(TaskEvent e) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
55 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
56 |
}); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
57 |
|
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
58 |
try { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
59 |
task.call(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
60 |
throw new AssertionError("no exception thrown"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
61 |
} catch (RuntimeException e) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
62 |
if (e.getCause() instanceof TaskEventError) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
63 |
TaskEventError tee = (TaskEventError) e.getCause(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
64 |
System.err.println("Exception thrown for " + tee.event + " as expected"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
65 |
} else { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
66 |
e.printStackTrace(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
5520
diff
changeset
|
67 |
throw new AssertionError("TaskEventError not thrown"); |
10 | 68 |
} |
69 |
} |
|
70 |
} |
|
71 |
} |
|
72 |
} |
|
73 |
||
74 |
class TaskEventError extends Error { |
|
75 |
public TaskEventError(TaskEvent ev) { |
|
76 |
event = ev; |
|
77 |
} |
|
78 |
||
79 |
TaskEvent event; |
|
80 |
} |