8245153: Unicode encoded double-quoted empty string does not compile

Fixed parsing of Unicode encoded double-quoted empty strings in c.s.t.j.p.JavaTokenizer::scanString

Reviewed-by: jlaskey
This commit is contained in:
Adam Sotona 2020-05-29 09:56:05 +02:00
parent 4d10ebba12
commit 5a57b9f8ec
2 changed files with 42 additions and 4 deletions
src/jdk.compiler/share/classes/com/sun/tools/javac/parser
test/langtools/tools/javac/8245153

@ -427,10 +427,8 @@ public class JavaTokenizer {
case 1: // Starting a string literal.
break;
case 2: // Starting an empty string literal.
// Start again but only consume one quote.
reader.reset(pos);
openCount = countChar('\"', 1);
break;
tk = Tokens.TokenKind.STRINGLITERAL;
return;
case 3: // Starting a text block.
// Check if preview feature is enabled for text blocks.
checkSourceLevel(pos, Feature.TEXT_BLOCKS);

@ -0,0 +1,40 @@
/*
* Copyright (c) 2020, 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 8245153
* @summary Unicode encoded double-quoted empty string does not compile
* @compile T8245153.java
*/
public class T8245153 {
String s0 = "";
String s1 = \u0022\u0022;
String s2 = "\u0022;
String s3 = \u0022";
String s4 = \u0022\\u0022\u0022;
}