author | lana |
Thu, 21 Jan 2016 09:46:01 -0800 | |
changeset 35340 | 38f7386ed942 |
parent 30846 | 2b3f379840f0 |
permissions | -rw-r--r-- |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
2 |
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
4 |
* |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
8 |
* |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
13 |
* accompanied this code). |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
14 |
* |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
18 |
* |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
21 |
* questions. |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
22 |
*/ |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
23 |
|
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
24 |
/* |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
25 |
* @test |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
26 |
* @bug 8029800 |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
27 |
* @summary String.toLowerCase()/toUpperCase is generally dangerous, check it is not used in langtools |
30846 | 28 |
* @modules jdk.jdeps/com.sun.tools.classfile |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
29 |
*/ |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
30 |
|
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
31 |
import java.io.*; |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
32 |
import java.util.*; |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
33 |
import javax.tools.*; |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
34 |
import com.sun.tools.classfile.*; |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
35 |
import com.sun.tools.classfile.ConstantPool.CONSTANT_Methodref_info; |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
36 |
|
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
37 |
public class NoStringToLower { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
38 |
public static void main(String... args) throws Exception { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
39 |
NoStringToLower c = new NoStringToLower(); |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
40 |
if (c.run(args)) |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
41 |
return; |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
42 |
|
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
43 |
if (is_jtreg()) |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
44 |
throw new Exception(c.errors + " errors occurred"); |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
45 |
else |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
46 |
System.exit(1); |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
47 |
} |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
48 |
|
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
49 |
static boolean is_jtreg() { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
50 |
return (System.getProperty("test.src") != null); |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
51 |
} |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
52 |
|
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
53 |
/** |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
54 |
* Main entry point. |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
55 |
*/ |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
56 |
boolean run(String... args) throws Exception { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
57 |
JavaCompiler c = ToolProvider.getSystemJavaCompiler(); |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
58 |
try (JavaFileManager fm = c.getStandardFileManager(null, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
59 |
JavaFileManager.Location javacLoc = findJavacLocation(fm); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
60 |
String[] pkgs = { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
61 |
"javax.annotation.processing", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
62 |
"javax.lang.model", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
63 |
"javax.tools", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
64 |
"com.sun.source", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
65 |
"com.sun.tools.classfile", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
66 |
"com.sun.tools.doclet", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
67 |
"com.sun.tools.doclint", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
68 |
"com.sun.tools.javac", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
69 |
"com.sun.tools.javadoc", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
70 |
"com.sun.tools.javah", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
71 |
"com.sun.tools.javap", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
72 |
"com.sun.tools.jdeps", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
73 |
"com.sun.tools.sjavac" |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
74 |
}; |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
75 |
for (String pkg: pkgs) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
76 |
for (JavaFileObject fo: fm.list(javacLoc, |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
77 |
pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
78 |
scan(fo); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
79 |
} |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
80 |
} |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
81 |
|
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22164
diff
changeset
|
82 |
return (errors == 0); |
22153
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
83 |
} |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
84 |
} |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
85 |
|
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
86 |
// depending on how the test is run, javac may be on bootclasspath or classpath |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
87 |
JavaFileManager.Location findJavacLocation(JavaFileManager fm) { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
88 |
JavaFileManager.Location[] locns = |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
89 |
{ StandardLocation.PLATFORM_CLASS_PATH, StandardLocation.CLASS_PATH }; |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
90 |
try { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
91 |
for (JavaFileManager.Location l: locns) { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
92 |
JavaFileObject fo = fm.getJavaFileForInput(l, |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
93 |
"com.sun.tools.javac.Main", JavaFileObject.Kind.CLASS); |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
94 |
if (fo != null) |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
95 |
return l; |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
96 |
} |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
97 |
} catch (IOException e) { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
98 |
throw new Error(e); |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
99 |
} |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
100 |
throw new IllegalStateException("Cannot find javac"); |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
101 |
} |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
102 |
|
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
103 |
/** |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
104 |
* Verify there are no references to String.toLowerCase() in a class file. |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
105 |
*/ |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
106 |
void scan(JavaFileObject fo) throws IOException { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
107 |
InputStream in = fo.openInputStream(); |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
108 |
try { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
109 |
ClassFile cf = ClassFile.read(in); |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
110 |
for (ConstantPool.CPInfo cpinfo: cf.constant_pool.entries()) { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
111 |
if (cpinfo.getTag() == ConstantPool.CONSTANT_Methodref) { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
112 |
CONSTANT_Methodref_info ref = (CONSTANT_Methodref_info) cpinfo; |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
113 |
String methodDesc = ref.getClassInfo().getName() + "." + ref.getNameAndTypeInfo().getName() + ":" + ref.getNameAndTypeInfo().getType(); |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
114 |
|
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
115 |
if ("java/lang/String.toLowerCase:()Ljava/lang/String;".equals(methodDesc)) { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
116 |
error("found reference to String.toLowerCase() in: " + fo.getName()); |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
117 |
} |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
118 |
if ("java/lang/String.toUpperCase:()Ljava/lang/String;".equals(methodDesc)) { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
119 |
error("found reference to String.toLowerCase() in: " + fo.getName()); |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
120 |
} |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
121 |
} |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
122 |
} |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
123 |
} catch (ConstantPoolException ignore) { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
124 |
} finally { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
125 |
in.close(); |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
126 |
} |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
127 |
} |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
128 |
|
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
129 |
/** |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
130 |
* Report an error. |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
131 |
*/ |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
132 |
void error(String msg) { |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
133 |
System.err.println("Error: " + msg); |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
134 |
errors++; |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
135 |
} |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
136 |
|
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
137 |
int errors; |
f9f06fcca59d
8029800: Flags.java uses String.toLowerCase without specifying Locale
jlahoda
parents:
diff
changeset
|
138 |
} |