# HG changeset patch # User rfield # Date 1452569556 28800 # Node ID 952a7b4652f001e876b236154272c7803bea4804 # Parent aacf94dab449d2642a7ced6c468dad9efd8b4971 8146368: JShell: couldn't smash the error when it's Japanese locale Reviewed-by: rfield Contributed-by: bitterfoxc@gmail.com diff -r aacf94dab449 -r 952a7b4652f0 langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java --- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java Mon Jan 11 08:41:00 2016 -0800 +++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java Mon Jan 11 19:32:36 2016 -0800 @@ -1468,7 +1468,7 @@ } } - 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); } diff -r aacf94dab449 -r 952a7b4652f0 langtools/src/jdk.jshell/share/classes/jdk/jshell/OuterWrap.java --- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/OuterWrap.java Mon Jan 11 08:41:00 2016 -0800 +++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/OuterWrap.java Mon Jan 11 19:32:36 2016 -0800 @@ -182,9 +182,9 @@ return null; } - @Override - public String toString() { - return "WrappedDiagnostic(" + getMessage(null) + ":" + getPosition() + ")"; - } + @Override + public String toString() { + return "WrappedDiagnostic(" + getMessage(null) + ":" + getPosition() + ")"; + } } } diff -r aacf94dab449 -r 952a7b4652f0 langtools/src/jdk.jshell/share/classes/jdk/jshell/TaskFactory.java --- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/TaskFactory.java Mon Jan 11 08:41:00 2016 -0800 +++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/TaskFactory.java Mon Jan 11 19:32:36 2016 -0800 @@ -33,7 +33,6 @@ 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 @@ LinkedHashMap diagMap = new LinkedHashMap<>(); for (Diagnostic 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 @@ 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 @@ 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); } diff -r aacf94dab449 -r 952a7b4652f0 langtools/src/jdk.jshell/share/classes/jdk/jshell/Unit.java --- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/Unit.java Mon Jan 11 08:41:00 2016 -0800 +++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/Unit.java Mon Jan 11 19:32:36 2016 -0800 @@ -50,6 +50,7 @@ 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 @@ 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()); diff -r aacf94dab449 -r 952a7b4652f0 langtools/src/jdk.jshell/share/classes/jdk/jshell/Util.java --- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/Util.java Mon Jan 11 08:41:00 2016 -0800 +++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/Util.java Mon Jan 11 19:32:36 2016 -0800 @@ -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 @@ 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()); } diff -r aacf94dab449 -r 952a7b4652f0 langtools/test/jdk/jshell/T8146368/JShellTest8146368.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/jdk/jshell/T8146368/JShellTest8146368.java Mon Jan 11 19:32:36 2016 -0800 @@ -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)); + } +} diff -r aacf94dab449 -r 952a7b4652f0 langtools/test/jdk/jshell/T8146368/JShellToolTest8146368.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/jdk/jshell/T8146368/JShellToolTest8146368.java Mon Jan 11 19:32:36 2016 -0800 @@ -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") + ); + } +}