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