Path: blob/master/test/jdk/com/sun/jdi/ArrayLengthDumpTest.java
41149 views
/*1* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4422141 469533826* @summary TTY: .length field for arrays in print statements in jdb not recognized27* TTY: dump <ArrayReference> command not implemented.28* @comment converted from test/jdk/com/sun/jdi/ArrayLengthDumpTest.sh29*30* @library /test/lib31* @build ArrayLengthDumpTest32* @run main/othervm ArrayLengthDumpTest33*/3435import lib.jdb.JdbCommand;36import lib.jdb.JdbTest;37import jdk.test.lib.process.OutputAnalyzer;3839import java.util.LinkedList;40import java.util.List;41import java.util.stream.Collectors;424344class ArrayLengthDumpTarg {45static final int [] i = {0,1,2,3,4,5,6};46String [] s = {"zero", "one", "two", "three", "four"};47String [][] t = {s, s, s, s, s, s, s, s, s, s, s};48int length = 5;4950private void bar() {51}5253private void foo() {54ArrayLengthDumpTarg u[] = { new ArrayLengthDumpTarg(),55new ArrayLengthDumpTarg(),56new ArrayLengthDumpTarg(),57new ArrayLengthDumpTarg(),58new ArrayLengthDumpTarg(),59new ArrayLengthDumpTarg() };60int k = u.length;61System.out.println(" u.length is: " + k);62k = this.s.length;63System.out.println(" this.s.length is: " + k);64k = this.t.length;65System.out.println(" this.t.length is: " + k);66k = this.t[1].length;67System.out.println("this.t[1].length is: " + k);68k = i.length;69System.out.println(" i.length is: " + k);70bar(); // @1 breakpoint71}7273public static void main(String[] args) {74ArrayLengthDumpTarg my = new ArrayLengthDumpTarg();75my.foo();76}77}7879public class ArrayLengthDumpTest extends JdbTest {80public static void main(String argv[]) {81new ArrayLengthDumpTest().run();82}8384public ArrayLengthDumpTest() {85super(DEBUGGEE_CLASS);86}8788private static final String DEBUGGEE_CLASS = ArrayLengthDumpTarg.class.getName();8990@Override91protected void runCases() {92setBreakpointsFromTestSource("ArrayLengthDumpTest.java", 1);9394// Run to breakpoint #195jdb.command(JdbCommand.run());9697List<String> reply = new LinkedList<>();98reply.addAll(jdb.command(JdbCommand.dump("this")));99reply.addAll(jdb.command(JdbCommand.dump("this.s.length")));100reply.addAll(jdb.command(JdbCommand.dump("this.s")));101reply.addAll(jdb.command(JdbCommand.dump("this.t.length")));102reply.addAll(jdb.command(JdbCommand.dump("this.t[1].length")));103reply.addAll(jdb.command(JdbCommand.dump("ArrayLengthDumpTarg.i.length")));104reply.addAll(jdb.command(JdbCommand.dump("this.length")));105106new OutputAnalyzer(reply.stream().collect(Collectors.joining(lineSeparator)))107// Test the fix for 4690242:108.shouldNotContain("No instance field or method with the name length in")109.shouldNotContain("No static field or method with the name length")110// Test the fix for 4695338:111.shouldContain("\"zero\", \"one\", \"two\", \"three\", \"four\"");112113jdb.contToExit(1);114}115116}117118119