8146368: JShell: couldn't smash the error when it's Japanese locale

Reviewed-by: rfield
This commit is contained in:
Shinya Yoshida 2016-01-11 19:32:36 -08:00 committed by Robert Field
parent d15f6a78b3
commit 6d4c26ee9c
7 changed files with 98 additions and 10 deletions

View File

@ -1468,7 +1468,7 @@ public class JShellTool {
}
}
for (String line : diag.getMessage(null).split("\\r?\\n")) {
for (String line : diag.getMessage(null).split("\\r?\\n")) { // TODO: Internationalize
if (!line.trim().startsWith("location:")) {
hard("%s%s", padding, line);
}

View File

@ -182,9 +182,9 @@ final class OuterWrap implements GeneralWrap {
return null;
}
@Override
public String toString() {
return "WrappedDiagnostic(" + getMessage(null) + ":" + getPosition() + ")";
}
@Override
public String toString() {
return "WrappedDiagnostic(" + getMessage(null) + ":" + getPosition() + ")";
}
}
}

View File

@ -33,7 +33,6 @@ import com.sun.tools.javac.api.JavacTool;
import com.sun.tools.javac.util.Context;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
@ -395,7 +394,7 @@ class TaskFactory {
LinkedHashMap<String, Diag> diagMap = new LinkedHashMap<>();
for (Diagnostic<? extends JavaFileObject> in : diagnostics.getDiagnostics()) {
Diag d = diag(in);
String uniqueKey = d.getCode() + ":" + d.getPosition() + ":" + d.getMessage(null);
String uniqueKey = d.getCode() + ":" + d.getPosition() + ":" + d.getMessage(PARSED_LOCALE);
diagMap.put(uniqueKey, d);
}
diags = new DiagList(diagMap.values());
@ -410,7 +409,7 @@ class TaskFactory {
String shortErrorMessage() {
StringBuilder sb = new StringBuilder();
for (Diag diag : getDiagnostics()) {
for (String line : diag.getMessage(null).split("\\r?\\n")) {
for (String line : diag.getMessage(PARSED_LOCALE).split("\\r?\\n")) {
if (!line.trim().startsWith("location:")) {
sb.append(line);
}
@ -422,7 +421,7 @@ class TaskFactory {
void debugPrintDiagnostics(String src) {
for (Diag diag : getDiagnostics()) {
state.debug(DBG_GEN, "ERROR --\n");
for (String line : diag.getMessage(null).split("\\r?\\n")) {
for (String line : diag.getMessage(PARSED_LOCALE).split("\\r?\\n")) {
if (!line.trim().startsWith("location:")) {
state.debug(DBG_GEN, "%s\n", line);
}

View File

@ -50,6 +50,7 @@ import static jdk.jshell.Snippet.Status.RECOVERABLE_DEFINED;
import static jdk.jshell.Snippet.Status.RECOVERABLE_NOT_DEFINED;
import static jdk.jshell.Snippet.Status.REJECTED;
import static jdk.jshell.Snippet.Status.VALID;
import static jdk.jshell.Util.PARSED_LOCALE;
import static jdk.jshell.Util.expunge;
/**
@ -456,7 +457,7 @@ final class Unit {
for (Diag diag : diags) {
if (diag.isError()) {
if (diag.isResolutionError()) {
String m = diag.getMessage(null);
String m = diag.getMessage(PARSED_LOCALE);
int symPos = m.indexOf(RESOLVE_ERROR_SYMBOL);
if (symPos >= 0) {
m = m.substring(symPos + RESOLVE_ERROR_SYMBOL.length());

View File

@ -25,6 +25,7 @@
package jdk.jshell;
import java.util.Locale;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import javax.lang.model.element.Name;
@ -40,6 +41,8 @@ class Util {
static final String REPL_CLASS_PREFIX = "$REPL";
static final String REPL_DOESNOTMATTER_CLASS_NAME = REPL_CLASS_PREFIX+"00DOESNOTMATTER";
static final Locale PARSED_LOCALE = Locale.ROOT;
static boolean isDoIt(Name name) {
return isDoIt(name.toString());
}

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2015, 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 8146368
* @summary Test Smashing Error when user language is Japanese
* @library /tools/lib /jdk/jshell
* @build KullaTesting
* @run testng/othervm -Duser.language=ja JShellTest8146368
*/
import static jdk.jshell.Snippet.Status.RECOVERABLE_NOT_DEFINED;
import org.testng.annotations.Test;
@Test
public class JShellTest8146368 extends KullaTesting {
public void test() {
assertEval("class A extends B {}", added(RECOVERABLE_NOT_DEFINED));
assertEval("und m() { return new und(); }", added(RECOVERABLE_NOT_DEFINED));
}
}

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2015, 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 8146368
* @summary Test Smashing Error when user language is Japanese
* @library /tools/lib /jdk/jshell
* @build ReplToolTesting
* @run testng/othervm -Duser.language=ja JShellToolTest8146368
*/
import org.testng.annotations.Test;
@Test
public class JShellToolTest8146368 extends ReplToolTesting {
public void test() {
test(
a -> assertCommand(a, "class A extends B {}", "| Added class A, however, it cannot be referenced until class B is declared\n"),
a -> assertCommand(a, "und m() { return new und(); }", "| Added method m(), however, it cannot be referenced until class und is declared\n")
);
}
}