1.1 --- a/src/share/classes/com/sun/tools/javac/parser/Scanner.java Thu Apr 16 11:23:02 2009 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/parser/Scanner.java Mon May 04 21:04:04 2009 -0700 1.3 @@ -317,7 +317,7 @@ 1.4 1.5 /** Read next character in character or string literal and copy into sbuf. 1.6 */ 1.7 - private void scanLitChar() { 1.8 + private void scanLitChar(boolean forBytecodeName) { 1.9 if (ch == '\\') { 1.10 if (buf[bp+1] == '\\' && unicodeConversionBp != bp) { 1.11 bp++; 1.12 @@ -357,6 +357,18 @@ 1.13 putChar('\"'); scanChar(); break; 1.14 case '\\': 1.15 putChar('\\'); scanChar(); break; 1.16 + case '|': case ',': case '?': case '%': 1.17 + case '^': case '_': case '{': case '}': 1.18 + case '!': case '-': case '=': 1.19 + if (forBytecodeName) { 1.20 + // Accept escape sequences for dangerous bytecode chars. 1.21 + // This is illegal in normal Java string or character literals. 1.22 + // Note that the escape sequence itself is passed through. 1.23 + putChar('\\'); putChar(ch); scanChar(); 1.24 + } else { 1.25 + lexError(bp, "illegal.esc.char"); 1.26 + } 1.27 + break; 1.28 default: 1.29 lexError(bp, "illegal.esc.char"); 1.30 } 1.31 @@ -365,6 +377,24 @@ 1.32 putChar(ch); scanChar(); 1.33 } 1.34 } 1.35 + private void scanLitChar() { 1.36 + scanLitChar(false); 1.37 + } 1.38 + 1.39 + /** Read next character in an exotic name #"foo" 1.40 + */ 1.41 + private void scanBytecodeNameChar() { 1.42 + switch (ch) { 1.43 + // reject any "dangerous" char which is illegal somewhere in the JVM spec 1.44 + // cf. http://blogs.sun.com/jrose/entry/symbolic_freedom_in_the_vm 1.45 + case '/': case '.': case ';': // illegal everywhere 1.46 + case '<': case '>': // illegal in methods, dangerous in classes 1.47 + case '[': // illegal in classes 1.48 + lexError(bp, "illegal.bytecode.ident.char", String.valueOf((int)ch)); 1.49 + break; 1.50 + } 1.51 + scanLitChar(true); 1.52 + } 1.53 1.54 /** Read fractional part of hexadecimal floating point number. 1.55 */ 1.56 @@ -915,6 +945,26 @@ 1.57 lexError(pos, "unclosed.str.lit"); 1.58 } 1.59 return; 1.60 + case '#': 1.61 + scanChar(); 1.62 + if (ch == '\"') { 1.63 + scanChar(); 1.64 + if (ch == '\"') 1.65 + lexError(pos, "empty.bytecode.ident"); 1.66 + while (ch != '\"' && ch != CR && ch != LF && bp < buflen) { 1.67 + scanBytecodeNameChar(); 1.68 + } 1.69 + if (ch == '\"') { 1.70 + name = names.fromChars(sbuf, 0, sp); 1.71 + token = IDENTIFIER; // even if #"int" or #"do" 1.72 + scanChar(); 1.73 + } else { 1.74 + lexError(pos, "unclosed.bytecode.ident"); 1.75 + } 1.76 + } else { 1.77 + lexError("illegal.char", String.valueOf((int)'#')); 1.78 + } 1.79 + return; 1.80 default: 1.81 if (isSpecial(ch)) { 1.82 scanOperator();