test/tools/javac/api/T6357331.java

changeset 1
9a66ca7c79fa
child 554
9d9f26857129
equal deleted inserted replaced
-1:000000000000 1:9a66ca7c79fa
1 /*
2 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
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 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24 /*
25 * @test
26 * @bug 6357331
27 * @summary NPE from JavacTask.getElements() after calling CompilationTask.run
28 */
29 import java.io.*;
30 import java.util.Arrays;
31 import javax.tools.*;
32 import com.sun.source.util.*;
33
34 public class T6357331
35 {
36 public static void main(String... args) {
37 JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
38 PrintWriter out = new PrintWriter(new StringWriter());
39 final JavacTask task = (JavacTask) (tool.getTask(out, null, null, null, null, null));
40
41 // set a listener to verify that IllegalStateException is not thrown
42 // during the compilation
43 task.setTaskListener(new TaskListener() {
44 public void started(TaskEvent e) {
45 task.getElements();
46 task.getTypes();
47 }
48 public void finished(TaskEvent e) { }
49 });
50
51 task.call();
52
53 // now the compilation is over, we expect IllegalStateException (not NPE)
54 try {
55 task.getElements();
56 throw new AssertionError("IllegalStateException not thrown");
57 }
58 catch (IllegalStateException e) {
59 // expected
60 }
61
62 try {
63 task.getTypes();
64 throw new AssertionError("IllegalStateException not thrown");
65 }
66 catch (IllegalStateException e) {
67 // expected
68 }
69 }
70 }

mercurial