6999438: remove support for exotic identifiers from JDK 7
Reviewed-by: mcimadamore
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Source.java Wed Nov 17 15:07:43 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Source.java Thu Nov 18 16:13:11 2010 -0800
@@ -174,9 +174,6 @@
public boolean allowUnderscoresInLiterals() {
return compareTo(JDK1_7) >= 0;
}
- public boolean allowExoticIdentifiers() {
- return compareTo(JDK1_7) >= 0;
- }
public boolean allowStringsInSwitch() {
return compareTo(JDK1_7) >= 0;
}
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Wed Nov 17 15:07:43 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Thu Nov 18 16:13:11 2010 -0800
@@ -2615,7 +2615,6 @@
String binaryName = fileManager.inferBinaryName(currentLoc, fo);
String simpleName = binaryName.substring(binaryName.lastIndexOf(".") + 1);
if (SourceVersion.isIdentifier(simpleName) ||
- fo.getKind() == JavaFileObject.Kind.CLASS ||
simpleName.equals("package-info"))
includeClassFile(p, fo);
break;
--- a/langtools/src/share/classes/com/sun/tools/javac/parser/Scanner.java Wed Nov 17 15:07:43 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/parser/Scanner.java Thu Nov 18 16:13:11 2010 -0800
@@ -66,10 +66,6 @@
*/
private boolean allowUnderscoresInLiterals;
- /** Allow exotic identifiers.
- */
- private boolean allowExoticIdentifiers;
-
/** The source language setting.
*/
private Source source;
@@ -143,7 +139,6 @@
allowBinaryLiterals = source.allowBinaryLiterals();
allowHexFloats = source.allowHexFloats();
allowUnderscoresInLiterals = source.allowBinaryLiterals();
- allowExoticIdentifiers = source.allowExoticIdentifiers(); // for invokedynamic
}
private static final boolean hexFloatsWork = hexFloatsWork();
@@ -295,7 +290,7 @@
/** Read next character in character or string literal and copy into sbuf.
*/
- private void scanLitChar(boolean forBytecodeName) {
+ private void scanLitChar() {
if (ch == '\\') {
if (buf[bp+1] == '\\' && unicodeConversionBp != bp) {
bp++;
@@ -335,18 +330,6 @@
putChar('\"'); scanChar(); break;
case '\\':
putChar('\\'); scanChar(); break;
- case '|': case ',': case '?': case '%':
- case '^': case '_': case '{': case '}':
- case '!': case '-': case '=':
- if (forBytecodeName) {
- // Accept escape sequences for dangerous bytecode chars.
- // This is illegal in normal Java string or character literals.
- // Note that the escape sequence itself is passed through.
- putChar('\\'); putChar(ch); scanChar();
- } else {
- lexError(bp, "illegal.esc.char");
- }
- break;
default:
lexError(bp, "illegal.esc.char");
}
@@ -355,24 +338,6 @@
putChar(ch); scanChar();
}
}
- private void scanLitChar() {
- scanLitChar(false);
- }
-
- /** Read next character in an exotic name #"foo"
- */
- private void scanBytecodeNameChar() {
- switch (ch) {
- // reject any "dangerous" char which is illegal somewhere in the JVM spec
- // cf. http://blogs.sun.com/jrose/entry/symbolic_freedom_in_the_vm
- case '/': case '.': case ';': // illegal everywhere
- case '<': case '>': // illegal in methods, dangerous in classes
- case '[': // illegal in classes
- lexError(bp, "illegal.bytecode.ident.char", String.valueOf((int)ch));
- break;
- }
- scanLitChar(true);
- }
private void scanDigits(int digitRadix) {
char saveCh;
@@ -970,30 +935,6 @@
lexError(pos, "unclosed.str.lit");
}
return;
- case '#':
- scanChar();
- if (ch == '\"') {
- if (!allowExoticIdentifiers) {
- lexError("unsupported.exotic.id", source.name);
- allowExoticIdentifiers = true;
- }
- scanChar();
- if (ch == '\"')
- lexError(pos, "empty.bytecode.ident");
- while (ch != '\"' && ch != CR && ch != LF && bp < buflen) {
- scanBytecodeNameChar();
- }
- if (ch == '\"') {
- name = names.fromChars(sbuf, 0, sp);
- token = IDENTIFIER; // even if #"int" or #"do"
- scanChar();
- } else {
- lexError(pos, "unclosed.bytecode.ident");
- }
- } else {
- lexError("illegal.char", String.valueOf((int)'#'));
- }
- return;
default:
if (isSpecial(ch)) {
scanOperator();
--- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Wed Nov 17 15:07:43 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Nov 18 16:13:11 2010 -0800
@@ -153,8 +153,6 @@
compiler.err.else.without.if=\
''else'' without ''if''
-compiler.err.empty.bytecode.ident=\
- empty bytecode identifier
compiler.err.empty.char.lit=\
empty character literal
compiler.err.encl.class.required=\
@@ -201,8 +199,6 @@
compiler.err.icls.cant.have.static.decl=\
inner classes cannot have static declarations
-compiler.err.illegal.bytecode.ident.char=\
- illegal bytecode identifier character: \\{0}
compiler.err.illegal.char=\
illegal character: \\{0}
compiler.err.illegal.char.for.encoding=\
@@ -472,8 +468,6 @@
compiler.err.types.incompatible.diff.ret=\
types {0} and {1} are incompatible; both define {2}, but with unrelated return types
-compiler.err.unclosed.bytecode.ident=\
- unclosed bytecode identifier
compiler.err.unclosed.char.lit=\
unclosed character literal
compiler.err.unclosed.comment=\
@@ -1269,10 +1263,6 @@
underscores in literals are not supported in -source {0}\n\
(use -source 7 or higher to enable underscores in literals)
-compiler.err.unsupported.exotic.id=\
- exotic identifiers #"___" are not supported in -source {0}\n\
-(use -source 7 or higher to enable exotic identifiers)
-
compiler.err.try.with.resources.not.supported.in.source=\
try-with-resources is not supported in -source {0}\n\
(use -source 7 or higher to enable try-with-resources)
--- a/langtools/test/tools/javac/diags/examples/EmptyBytecodeIdent.java Wed Nov 17 15:07:43 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-// key: compiler.err.empty.bytecode.ident
-
-class EmptyBytecodeIdent {
- int #"" = 3;
-}
--- a/langtools/test/tools/javac/diags/examples/IllegalBytecodeIdentChar.java Wed Nov 17 15:07:43 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-// key: compiler.err.illegal.bytecode.ident.char
-
-class IllegalBytecodeIdentChar {
- int #"abc/def" = 3;
-}
--- a/langtools/test/tools/javac/diags/examples/UnclosedBytecodeIdent.java Wed Nov 17 15:07:43 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-// key: compiler.err.unclosed.bytecode.ident
-
-class UnclosedBytecodeIdent {
- int #"abc
-}
--- a/langtools/test/tools/javac/diags/examples/UnsupportedExoticID.java Wed Nov 17 15:07:43 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-// key: compiler.err.unsupported.exotic.id
-// options: -source 6
-
-class UnsupportedExoticID {
- void m() {
- Object #"Hello!" = null;
- }
-}
--- a/langtools/test/tools/javac/meth/InvokeDyn.java Wed Nov 17 15:07:43 2010 -0800
+++ b/langtools/test/tools/javac/meth/InvokeDyn.java Thu Nov 18 16:13:11 2010 -0800
@@ -58,7 +58,7 @@
ojunk = InvokeDynamic.greet(x, "mundus", 456);
ojunk = InvokeDynamic.greet(x, "kosmos", 789);
ojunk = (String) InvokeDynamic.cogitate(10.11121, 3.14);
- InvokeDynamic.#"yow: what I mean to say is, please treat this one specially"(null);
+ //InvokeDynamic.#"yow: what I mean to say is, please treat this one specially"(null);
ijunk = (int) InvokeDynamic.invoke("goodbye");
}
}
--- a/langtools/test/tools/javac/meth/InvokeDynTrans.java Wed Nov 17 15:07:43 2010 -0800
+++ b/langtools/test/tools/javac/meth/InvokeDynTrans.java Thu Nov 18 16:13:11 2010 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008-2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -53,7 +53,7 @@
InvokeDynamic.greet(x, "mundus", 456);
InvokeDynamic.greet(x, "kosmos", 789);
InvokeDynamic.<String>cogitate(10.11121, 3.14);
- InvokeDynamic.<void>#"yow: what I mean to say is, please treat this one specially"(null);
+ //InvokeDynamic.<void>#"yow: what I mean to say is, please treat this one specially"(null);
InvokeDynamic.<int>invoke("goodbye");
}
}
--- a/langtools/test/tools/javac/meth/InvokeDynTrans.out Wed Nov 17 15:07:43 2010 -0800
+++ b/langtools/test/tools/javac/meth/InvokeDynTrans.out Thu Nov 18 16:13:11 2010 -0800
@@ -1,6 +1,5 @@
InvokeDynTrans.java:55:39: compiler.warn.type.parameter.on.polymorphic.signature
-InvokeDynTrans.java:56:91: compiler.warn.type.parameter.on.polymorphic.signature
InvokeDynTrans.java:57:34: compiler.warn.type.parameter.on.polymorphic.signature
- compiler.err.warnings.and.werror
1 error
-3 warnings
+2 warnings
--- a/langtools/test/tools/javac/quid/QuotedIdent.java Wed Nov 17 15:07:43 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +0,0 @@
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 6746458
- * @summary Verify correct lexing of quoted identifiers.
- * @author jrose
- * @ignore 6877225 test fails on Windows:
- * QuotedIdent.java:81: error while writing QuotedIdent.*86: PATH\QuotedIdent$*86.class
- * (The filename, directory name, or volume label syntax is incorrect)
- *
- * @library ..
- * @compile -source 7 -target 7 -XDinvokedynamic QuotedIdent.java
- * @run main quid.QuotedIdent
- */
-
-/*
- * Standalone testing:
- * <code>
- * $ cd $MY_REPO_DIR/langtools
- * $ (cd make; make)
- * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent.java
- * $ java -version # should print 1.6 or later
- * $ java -cp dist quid.QuotedIdent
- * </code>
- */
-
-package quid;
-
-public class QuotedIdent {
- static void check(int testid, String have, String expect)
- throws RuntimeException {
- if ((have == null && have != expect) ||
- (have != null && !have.equals(expect))) {
- String msg =
- "TEST " + testid + ": HAVE \"" +
- have + "\" EXPECT \"" + expect + "\"";
- System.out.println("StringConversion: " + msg);
- throw new RuntimeException(msg);
- }
- }
-
- // negative tests:
- //static class #"" { } //BAD empty ident name
- //static class #"<foo>" { } //BAD bad char in ident name
- /*static class /*(//BAD ident name interrupted by newline) #"jump:
- " { } /* uncomment previous line to attempt class w/ bad name */
-
- static class #"int" extends Number {
- final int #"int";
- #"int"(int #"int") {
- this.#"int" = #"int";
- }
- static #"int" valueOf(int #"int") {
- return new #"int"(#"int");
- }
- public int intValue() { return #"int"; }
- public long longValue() { return #"int"; }
- public float floatValue() { return #"int"; }
- public double doubleValue() { return #"int"; }
- public String toString() { return String.valueOf(#"int"); }
- }
-
- class #"*86" {
- String #"555-1212"() { return "[*86.555-1212]"; }
- }
- static#"*86"#"MAKE-*86"() { // note close spacing
- return new QuotedIdent().new#"*86"();
- }
-
- static String bar() { return "[bar]"; }
-
- public static void main(String[] args) throws Exception {
- String s;
-
- String #"sticky \' wicket" = "wicked ' stick";
- s = #"sticky ' wicket";
- check(11, s, "wicked \' stick");
- check(12, #"s", s);
- check(13, #"\163", s);
-
- s = #"QuotedIdent".bar();
- check(21, s, "[bar]");
-
- s = #"int".valueOf(123).toString();
- check(22, s, "123");
-
- s = #"MAKE-*86"().#"555-1212"();
- check(23, s, "[*86.555-1212]");
-
- class#"{{{inmost}}}" { }
- s = new#"{{{inmost}}}"().getClass().getName();
- if (!s.endsWith("{{{inmost}}}"))
- check(24, s, "should end with \"{{{inmost}}}\"");
-
- s = #"Yog-Shoggoth".#"(nameless ululation)";
- check(25, s, "Tekeli-li!");
-
- s = #"int".class.getName();
- check(31, s, QuotedIdent.class.getName()+"$int");
-
- Class<?> x86 = Class.forName(QuotedIdent.class.getName()+"$*86");
- if (x86 != #"*86".class)
- check(32, "reflected "+x86, "static "+#"*86".class);
-
- s = (String) x86.getDeclaredMethod("555-1212").invoke(#"MAKE-*86"());
- check(31, s, "[*86.555-1212]");
-
- System.out.println("OK");
- }
-}
-
-interface #"Yog-Shoggoth" {
- final String #"(nameless ululation)" = "Tekeli-li!";
-}
--- a/langtools/test/tools/javac/quid/QuotedIdent2.java Wed Nov 17 15:07:43 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @bug 6746458
- * @summary Verify correct separate compilation of classes with extended identifiers.
- * @author jrose
- * @ignore 6877225 test fails on Windows:
- * QuotedIdent.java:81: error while writing QuotedIdent.*86: PATH\QuotedIdent$*86.class
- * (The filename, directory name, or volume label syntax is incorrect)
- *
- * @library ..
- * @compile -source 7 -target 7 -XDinvokedynamic QuotedIdent.java
- * @run main quid.QuotedIdent2
- */
-/*
- * Standalone testing:
- * <code>
- * $ cd $MY_REPO_DIR/langtools
- * $ (cd make; make)
- * $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent.java
- * $ ./dist/bootstrap/bin/javac -d dist -cp dist test/tools/javac/quid/QuotedIdent2.java
- * $ java -version # should print 1.6 or later
- * $ java -cp dist QuotedIdent2
- * </code>
- */
-
-package quid;
-
-import quid.QuotedIdent.*;
-import quid.QuotedIdent.#"*86";
-import static quid.QuotedIdent.#"MAKE-*86";
-
-public class QuotedIdent2 {
- static void check(int testid, String have, String expect)
- throws RuntimeException {
- QuotedIdent.check(testid, have, expect);
- }
-
- public static void main(String[] args) throws Exception {
- String s;
-
- s = #"int".valueOf(123).toString();
- check(22, s, "123");
-
- s = #"MAKE-*86"().#"555-1212"();
- check(23, s, "[*86.555-1212]");
-
- s = #"Yog-Shoggoth".#"(nameless ululation)";
- check(25, s, "Tekeli-li!");
-
- s = QuotedIdent.#"int".class.getName();
- check(31, s, QuotedIdent.class.getName()+"$int");
-
- Class<?> x86 = Class.forName(QuotedIdent.class.getName()+"$*86");
- if (x86 != #"*86".class)
- check(32, "reflected "+x86, "static "+#"*86".class);
-
- s = (String) x86.getDeclaredMethod("555-1212").invoke(QuotedIdent.#"MAKE-*86"());
- check(31, s, "[*86.555-1212]");
-
- System.out.println("OK");
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/quid/T6999438.java Thu Nov 18 16:13:11 2010 -0800
@@ -0,0 +1,9 @@
+/* @test /nodynamiccopyright/
+ * @bug 6999438
+ * @summary remove support for exotic identifiers from JDK 7
+ * @compile/fail/ref=T6999438.out -XDrawDiagnostics -source 7 T6999438.java
+ */
+
+class Test {
+ int #"not supported";
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/quid/T6999438.out Thu Nov 18 16:13:11 2010 -0800
@@ -0,0 +1,6 @@
+T6999438.java:8:9: compiler.err.illegal.char: 35
+T6999438.java:8:10: compiler.err.illegal.start.of.type
+T6999438.java:8:25: compiler.err.expected: token.identifier
+T6999438.java:8:26: compiler.err.expected: ';'
+T6999438.java:9:2: compiler.err.premature.eof
+5 errors