# HG changeset patch # User rfield # Date 1482520670 28800 # Node ID 22c8c025a6515a2ebda92971aba37b5d94a8fcfd # Parent bcdba0c2679314d15301cebbf21f8cb7d9ab88db 8171892: JShell: incorrect printing of multidemensional arrays 8171387: jshell tool: message inconsistencies Reviewed-by: sundar, dlsmith diff -r bcdba0c26793 -r 22c8c025a651 langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties --- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties Thu Dec 22 18:48:42 2016 +0000 +++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/resources/l10n.properties Fri Dec 23 11:17:50 2016 -0800 @@ -150,8 +150,8 @@ jshell.console.see.more = jshell.console.see.javadoc = jshell.console.see.help = -jshell.console.see.next.page = -- Press space for next page, Q to quit. -- -jshell.console.see.next.javadoc = -- Press space for next javadoc, Q to quit. -- +jshell.console.see.next.page = +jshell.console.see.next.javadoc = jshell.console.no.javadoc = jshell.console.do.nothing = Do nothing jshell.console.choice = Choice: \ diff -r bcdba0c26793 -r 22c8c025a651 langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/DirectExecutionControl.java --- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/DirectExecutionControl.java Thu Dec 22 18:48:42 2016 +0000 +++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/DirectExecutionControl.java Fri Dec 23 11:17:50 2016 -0800 @@ -202,12 +202,27 @@ } else if (value instanceof Character) { return "'" + value + "'"; } else if (value.getClass().isArray()) { - String tn = value.getClass().getTypeName(); + int dims = 0; + Class t = value.getClass(); + while (true) { + Class ct = t.getComponentType(); + if (ct == null) { + break; + } + ++dims; + t = ct; + } + String tn = t.getTypeName(); int len = Array.getLength(value); StringBuilder sb = new StringBuilder(); - sb.append(tn.substring(tn.lastIndexOf('.') + 1, tn.length() - 1)); + sb.append(tn.substring(tn.lastIndexOf('.') + 1, tn.length())); + sb.append("["); sb.append(len); - sb.append("] { "); + sb.append("]"); + for (int i = 1; i < dims; ++i) { + sb.append("[]"); + } + sb.append(" { "); for (int i = 0; i < len; ++i) { sb.append(valueString(Array.get(value, i))); if (i < len - 1) { diff -r bcdba0c26793 -r 22c8c025a651 langtools/test/jdk/jshell/SimpleRegressionTest.java --- a/langtools/test/jdk/jshell/SimpleRegressionTest.java Thu Dec 22 18:48:42 2016 +0000 +++ b/langtools/test/jdk/jshell/SimpleRegressionTest.java Fri Dec 23 11:17:50 2016 -0800 @@ -22,7 +22,7 @@ */ /* - * @test 8130450 8158906 8154374 8166400 + * @test 8130450 8158906 8154374 8166400 8171892 * @summary simple regression test * @build KullaTesting TestingInputStream * @run testng SimpleRegressionTest @@ -150,7 +150,7 @@ assertEval("C.class.getClassLoader() == Thread.currentThread().getContextClassLoader()", "true"); } - public void testArayRepresentation() { + public void testArrayRepresentation() { assertEval("new int[4]", "int[4] { 0, 0, 0, 0 }"); assertEval("new int[0]", "int[0] { }"); assertEval("new byte[2]", "byte[2] { 0, 0 }"); @@ -162,8 +162,24 @@ assertEval("new char[] { 'a', 34, 77 }", "char[3] { 'a', '\"', 'M' }"); assertEval("new boolean[] { false, true }", "boolean[2] { false, true }"); assertEval("new int[][] { new int[] {44, 55}, new int[] {88,99}}", - "int[][2] { int[2] { 44, 55 }, int[2] { 88, 99 } }"); + "int[2][] { int[2] { 44, 55 }, int[2] { 88, 99 } }"); assertEval("new Object[] { \"howdy\", new int[] { 33, 44, 55 }, new String[] { \"up\", \"down\" }}", "Object[3] { \"howdy\", int[3] { 33, 44, 55 }, String[2] { \"up\", \"down\" } }"); } + + public void testMultiDimArrayRepresentation() { + assertEval("new int[3][1]", + "int[3][] { int[1] { 0 }, int[1] { 0 }, int[1] { 0 } }"); + assertEval("new int[3][]", + "int[3][] { null, null, null }"); + assertEval("new int[][] { new int[] {44}, new int[] {77, 88,99}}", + "int[2][] { int[1] { 44 }, int[3] { 77, 88, 99 } }"); + assertEval("new String[3][1]", + "String[3][] { String[1] { null }, String[1] { null }, String[1] { null } }"); + assertEval("class C { }"); + assertEval("new C[3][2]", + "C[3][] { C[2] { null, null }, C[2] { null, null }, C[2] { null, null } }"); + assertEval("new boolean[2][1][3]", + "boolean[2][][] { boolean[1][] { boolean[3] { false, false, false } }, boolean[1][] { boolean[3] { false, false, false } } }"); + } }