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/javap/T8033180.java
32285 views
1
/*
2
* Copyright (c) 2014, 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 8033180
27
* @summary Bad newline characters
28
*/
29
30
import java.io.*;
31
import java.util.*;
32
33
public class T8033180 {
34
35
public static void main(String... args) throws Exception {
36
new T8033180().run();
37
}
38
39
void run() throws Exception {
40
// fast-track this case, because test cannot fail in this case
41
if (lineSep.equals(nl))
42
return;
43
44
test("-help");
45
test("-version");
46
47
if (errors > 0)
48
throw new Exception(errors + " errors occurred");
49
}
50
51
static final String lineSep = System.getProperty("line.separator");
52
static final String nl = "\n";
53
54
void test(String... opts) throws Exception {
55
System.err.println("test " + Arrays.asList(opts));
56
List<String> args = new ArrayList<String>();
57
args.addAll(Arrays.asList(opts));
58
StringWriter sw = new StringWriter();
59
PrintWriter pw = new PrintWriter(sw);
60
int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw);
61
pw.close();
62
String out = sw.toString();
63
if (rc != 0)
64
throw new Exception("javap failed unexpectedly: rc=" + rc);
65
66
// remove all valid platform newline sequences
67
String out2 = out.replace(lineSep, "");
68
69
// count the remaining simple newline characters
70
int count = 0;
71
int i = out2.indexOf(nl, 0);
72
while (i != -1) {
73
count++;
74
i = out2.indexOf(nl, i + nl.length());
75
}
76
77
if (count > 0)
78
error(count + " newline characters found");
79
}
80
81
void error(String msg) {
82
System.err.println("Error: " + msg);
83
errors++;
84
}
85
86
int errors = 0;
87
}
88
89
90