author | bobv |
Tue, 07 Nov 2017 10:30:53 -0500 | |
changeset 47801 | c7b50c23ea71 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
25453
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
25453
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
25453
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
4 |
* |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
8 |
* |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
14 |
* |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
18 |
* |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
21 |
* questions. |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
22 |
*/ |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
23 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
24 |
/* |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
25 |
* @test |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
26 |
* @bug 8050106 |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
27 |
* @summary JavaCompiler relies on inappropriate result from comparison |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
25453
diff
changeset
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.code |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
25453
diff
changeset
|
29 |
* jdk.compiler/com.sun.tools.javac.jvm |
25453
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
30 |
*/ |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
31 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
32 |
import java.io.*; |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
33 |
import java.util.*; |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
34 |
import com.sun.tools.javac.code.Source; |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
35 |
import com.sun.tools.javac.jvm.Target; |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
36 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
37 |
public class SourceTargetTest { |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
38 |
public static void main(String... args) throws Exception { |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
39 |
SourceTargetTest t = new SourceTargetTest(); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
40 |
t.run(); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
41 |
} |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
42 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
43 |
public void run() throws Exception { |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
44 |
try (FileWriter out = new FileWriter("C.java")) { |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
45 |
out.write("class C { }"); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
46 |
} |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
47 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
48 |
for (Source s: Source.values()) { |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
49 |
test(s, null, "source", getKind(s, Source.MIN)); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
50 |
} |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
51 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
52 |
for (Target t: Target.values()) { |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
53 |
test(Source.values()[0], t, "target", getKind(t, Target.MIN)); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
54 |
} |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
55 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
56 |
if (errors > 0) |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
57 |
throw new Exception(errors + " errors occurred"); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
58 |
} |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
59 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
60 |
void test(Source s, Target t, String select, Kind kind) { |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
61 |
System.err.println("Test: source:" + s + ", target:" + t + " " + select + " " + kind); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
62 |
List<String> args = new ArrayList<>(); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
63 |
args.add("-XDrawDiagnostics"); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
64 |
args.add("-source"); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
65 |
args.add(s.name); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
66 |
if (t != null) { |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
67 |
args.add("-target"); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
68 |
args.add(t.name); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
69 |
} |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
70 |
args.add("C.java"); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
71 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
72 |
StringWriter sw = new StringWriter(); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
73 |
PrintWriter pw = new PrintWriter(sw); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
74 |
int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
75 |
pw.close(); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
76 |
String out = sw.toString(); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
77 |
System.err.print(out); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
78 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
79 |
switch (kind) { |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
80 |
case INVALID: |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
81 |
check(out, "removed." + select, true); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
82 |
check(out, "obsolete." + select, false); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
83 |
break; |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
84 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
85 |
case OBSOLETE: |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
86 |
check(out, "removed." + select, false); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
87 |
check(out, "obsolete." + select, true); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
88 |
break; |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
89 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
90 |
case VALID: |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
91 |
check(out, "removed." + select, false); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
92 |
check(out, "obsolete." + select, false); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
93 |
break; |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
94 |
} |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
95 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
96 |
System.err.println(); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
97 |
} |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
98 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
99 |
enum Kind { INVALID, OBSOLETE, VALID }; |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
100 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
101 |
<T extends Comparable<T>> Kind getKind(T t1, T t2) { |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
102 |
if (t1.compareTo(t2) < 0) |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
103 |
return Kind.INVALID; |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
104 |
else if (t1 == t2) |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
105 |
return Kind.OBSOLETE; |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
106 |
else |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
107 |
return Kind.VALID; |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
108 |
} |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
109 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
110 |
void check(String out, String text, boolean expect) { |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
111 |
if (out.contains(text) == expect) { |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
112 |
if (expect) |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
113 |
System.err.println("expected string found: " + text); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
114 |
else |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
115 |
System.err.println("string not found, as expected: " + text); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
116 |
} else { |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
117 |
if (expect) |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
118 |
error("expected string not found: " + text); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
119 |
else |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
120 |
error("unexpected string found: " + text); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
121 |
} |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
122 |
} |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
123 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
124 |
void error(String msg) { |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
125 |
System.err.println("error: " + msg); |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
126 |
errors++; |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
127 |
} |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
128 |
|
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
129 |
int errors; |
be80cf0463b3
8050106: JavaCompiler relies on inappropriate result from comparison
jjg
parents:
diff
changeset
|
130 |
} |