1 #!/bin/sh 2 3 # 4 # Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 # 7 # This code is free software; you can redistribute it and/or modify it 8 # under the terms of the GNU General Public License version 2 only, as 9 # published by the Free Software Foundation. 10 # 11 # This code is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 # version 2 for more details (a copy is included in the LICENSE file that 15 # accompanied this code). 16 # 17 # You should have received a copy of the GNU General Public License version 18 # 2 along with this work; if not, write to the Free Software Foundation, 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 # or visit www.oracle.com if you need additional information or have any 23 # questions. 24 # 25 26 # @test 27 # @bug 4511950 4843082 28 # @summary 1. jdb's expression evaluation doesn't perform string conversion properly 29 # 2. TTY: run on expression evaluation 30 # @author jim/suvasis mukherjee 31 # 32 # @key intermittent 33 # @run shell StringConvertTest.sh 34 35 # Run this script to see the bug. See comments at the end 36 # of the .java file for info on what the bug looks like. 37 38 # These are variables that can be set to control execution 39 40 #pkg=untitled7 41 classname=StringConvertTest 42 compileOptions=-g 43 #java=java_g 44 #mode=-Xcomp 45 46 #jdbOptions=-dbgtrace 47 createJavaFile() 48 { 49 cat <<EOF > $1.java.1 50 51 class $classname { 52 String me; 53 static JJ1 x1; 54 static JJ2 x2; 55 static JJ2[] x3 = new JJ2[2]; 56 static String x4 = "abc"; 57 static int ii = 89; 58 static String grower = "grower"; 59 static StringBuffer sbGrower = new StringBuffer("sbGrower"); 60 int ivar = 89; 61 $classname(String xx) { 62 me = xx; 63 } 64 65 static String fred() { 66 return "a static method"; 67 } 68 69 void gus() { 70 int gusLoc = 1; 71 StringBuffer sbTim = new StringBuffer("tim"); 72 int kk = 1; //@1 breakpoint 73 } 74 75 static String growit(String extra) { 76 grower += extra; 77 return grower; 78 } 79 80 static String sbGrowit(String extra) { 81 sbGrower.append(extra); 82 return sbGrower.toString(); 83 } 84 85 public static void main(String[] args) { 86 x1 = new JJ1("first JJ1"); 87 x2 = new JJ2("first JJ2"); 88 x3[0] = new JJ2("array0"); 89 x3[1] = new JJ2("array1"); 90 $classname loc1 = new $classname("first me"); 91 92 // These just show what output should look like 93 System.out.println("x1 = " + x1); 94 System.out.println("x2 = " + x2); 95 System.out.println("x3.toString = " + x3.toString()); 96 System.out.println("x4.toString = " + x4.toString()); 97 98 // Dont want to call growit since it would change 99 // the value. 100 101 System.out.println("loc1 = " + loc1); 102 System.out.println("-" + loc1); 103 loc1.gus(); 104 } 105 106 // This does not have a toString method 107 static class JJ1 { 108 String me; 109 110 JJ1(String whoAmI) { 111 me = whoAmI; 112 } 113 } 114 115 // This has a toString method 116 static class JJ2 { 117 String me; 118 119 JJ2(String whoAmI) { 120 me = whoAmI; 121 } 122 public String toString() { 123 return me; 124 } 125 126 public int meth1() { 127 return 89; 128 } 129 } 130 } 131 132 EOF 133 } 134 135 # This is called to feed cmds to jdb. 136 dojdbCmds() 137 { 138 setBkpts @1 139 runToBkpt @1 140 141 # Each print without the 'toString()' should print the 142 # same thing as the following print with the toString(). 143 # The print 1s are just spacers 144 145 cmd print $classname.x1 146 cmd print "$classname.x1.toString()" 147 cmd print 1 148 149 cmd print $classname.x2 150 cmd print "$classname.x2.toString()" 151 cmd print 1 152 153 # An unreported bug: this isn't handled correctly. 154 # If we uncomment this line, we will get an 'instance of...' line 155 # which will cause the test to fail. 156 #cmd print "(Object)($classname.x3)" 157 cmd print "((Object)$classname.x3).toString()" 158 cmd print 1 159 160 cmd print $classname.x4 161 cmd print "$classname.x4.toString()" 162 cmd print 1 163 164 # Make sure jdb doesn't call a method multiple times. 165 cmd print "$classname.growit(\"xyz\")" 166 cmd eval "$classname.sbGrower.append(\"xyz\")" 167 cmd print 1 168 169 cmd eval "sbTim.toString()" 170 cmd print 1 171 172 cmd print this 173 cmd print "this.toString()" 174 cmd print 1 175 176 # A possible bug is that this ends up with multiple "s 177 cmd print '"--" + '$classname.x1 178 cmd print 1 179 180 # This too 181 cmd print "$classname.x4 + 2" 182 cmd print 1 183 184 cmd print "this.ivar" 185 cmd print gusLoc 186 cmd print 1 187 } 188 189 mysetup() 190 { 191 if [ -z "$TESTSRC" ] ; then 192 TESTSRC=. 193 fi 194 195 for ii in . $TESTSRC $TESTSRC/.. ; do 196 if [ -r "$ii/ShellScaffold.sh" ] ; then 197 . $ii/ShellScaffold.sh 198 break 199 fi 200 done 201 } 202 203 # You could replace this next line with the contents 204 # of ShellScaffold.sh and this script will run just the same. 205 mysetup 206 207 runit 208 jdbFailIfPresent '""' 209 jdbFailIfPresent 'instance of' 210 jdbFailIfPresent 'xyzxyz' 211 pass