Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/tools/javac/6400383/T6400383.java
41149 views
1
/*
2
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. 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 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.
22
*/
23
24
/*
25
* @test
26
* @bug 6400383
27
* @summary directory foo.java on javac command line causes javac to crash
28
* @modules jdk.compiler/com.sun.tools.javac.api
29
*/
30
31
import java.io.*;
32
import com.sun.tools.javac.api.*;
33
34
public class T6400383 {
35
public static void main(String... args) {
36
File foo = new File("foo.java");
37
foo.delete();
38
39
// case 1: file not found
40
JavacTool tool = JavacTool.create();
41
StringStream out = new StringStream();
42
tool.run(null, out, out, foo.getPath());
43
check(out.toString());
44
45
46
// case 2: file is a directory
47
out.clear();
48
try {
49
foo.mkdir();
50
tool.run(null, out, out, foo.getPath());
51
check(out.toString());
52
} finally {
53
foo.delete();
54
}
55
}
56
57
private static void check(String s) {
58
System.err.println(s);
59
// If the compiler crashed and caught the error, it will print out
60
// the "oh golly, I crashed!" message, which will contain the Java
61
// name of the exception in the stack trace ... so look for the
62
// string "Exception" or "Error".
63
if (s.indexOf("Exception") != -1 || s.indexOf("Error") != -1)
64
throw new AssertionError("found exception");
65
}
66
67
private static class StringStream extends OutputStream {
68
public void write(int i) {
69
sb.append((char) i);
70
}
71
72
void clear() {
73
sb.setLength(0);
74
}
75
76
public String toString() {
77
return sb.toString();
78
}
79
80
private StringBuilder sb = new StringBuilder();
81
}
82
}
83
84