Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/EvalArgs.sh
38855 views
#!/bin/sh12#3# Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.4# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.5#6# This code is free software; you can redistribute it and/or modify it7# under the terms of the GNU General Public License version 2 only, as8# published by the Free Software Foundation.9#10# This code is distributed in the hope that it will be useful, but WITHOUT11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13# version 2 for more details (a copy is included in the LICENSE file that14# accompanied this code).15#16# You should have received a copy of the GNU General Public License version17# 2 along with this work; if not, write to the Free Software Foundation,18# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19#20# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21# or visit www.oracle.com if you need additional information or have any22# questions.23#2425# @test26# @bug 466314627# @summary Arguments match no method error28# @author Jim Holmlund/Suvasis29#30# @run shell/timeout=300 EvalArgs.sh3132# The bug is that, for example, if a String is passed33# as an arg to a func where an Object is expected,34# the above error occurs. jdb doesnt notice that this is35# legal because String is an instance of Object.363738# These are variables that can be set to control execution3940#pkg=untitled741classname=EvalArgs42#compileOptions=-g43#java="java_g"4445createJavaFile()46{47cat <<EOF > $classname.java.148public class $classname {4950static jj1 myjj1;51static jj2 myjj2;52static oranges myoranges;53static boolean jjboolean = true;54static byte jjbyte = 1;55static char jjchar = 'a';56static double jjdouble = 2.2;57static float jjfloat = 3.1f;58static int jjint = 4;59static long jjlong = 5;60static short jjshort = 6;61static int[] jjintArray = {7, 8};62static float[] jjfloatArray = {9.1f, 10.2f};636465public static void main(String args[]) {66myjj1 = new jj1();67myjj2 = new jj2();68myoranges = new oranges();6970// prove that these work71System.out.println( ffjj1(myjj1));72System.out.println( ffjj1(myjj2));7374System.out.println("$classname.ffoverload($classname.jjboolean) = " +75$classname.ffoverload($classname.jjboolean));76System.out.println("$classname.ffoverload($classname.jjbyte) = " +77$classname.ffoverload($classname.jjbyte));78System.out.println("$classname.ffoverload($classname.jjchar) = " +79$classname.ffoverload($classname.jjchar));80System.out.println("$classname.ffoverload($classname.jjdouble) = " +81$classname.ffoverload($classname.jjdouble));828384//This doesn't even compile85//System.out.println( "ffintArray(jjfloatArray) = " + ffintArray(jjfloatArray));86gus();87}8889static void gus() {90int x = 0; // @1 breakpoint91}9293public static String ffjj1(jj1 arg) {94return arg.me;95}9697public static String ffjj2(jj2 arg) {98return arg.me;99}100101static String ffboolean(boolean p1) {102return "ffbool: p1 = " + p1;103}104105static String ffbyte(byte p1) {106return "ffbyte: p1 = " + p1;107}108109static String ffchar(char p1) {110return "ffchar: p1 = " + p1;111}112113static String ffdouble(double p1) {114return "ffdouble: p1 = " + p1;115}116117static String fffloat(float p1) {118return "fffloat: p1 = " + p1;119}120121static String ffint(int p1) {122return "ffint: p1 = " + p1;123}124125static String fflong(long p1) {126return "fflong: p1 = " + p1;127}128129static String ffshort(short p1) {130return "ffshort: p1 = " + p1;131}132133static String ffintArray(int[] p1) {134return "ffintArray: p1 = " + p1;135}136137// Overloaded funcs138public static String ffoverload(jj1 arg) {139return arg.me;140}141142static String ffoverload(boolean p1) {143return "ffoverload: boolean p1 = " + p1;144}145/***146static String ffoverload(byte p1) {147return "ffoverload: byte p1 = " + p1;148}149***/150static String ffoverload(char p1) {151return "ffoverload: char p1 = " + p1;152}153154static String ffoverload(double p1) {155return "ffoverload: double p1 = " + p1;156}157158static String ffoverload(float p1) {159return "ffoverload: float p1 = " + p1;160}161/***162static String ffoverload(int p1) {163return "ffoverload: int p1 = " + p1;164}165***/166static String ffoverload(long p1) {167return "ffoverload: long p1 = " + p1;168}169170static String ffoverload(short p1) {171return "ffoverload: short p1 = " + p1;172}173174static String ffoverload(int[] p1) {175return "ffoverload: int array p1 = " + p1;176}177178static class jj1 {179String me;180jj1() {181me = "jj1name";182}183public String toString() {184return me;185}186187}188189static class jj2 extends jj1 {190jj2() {191super();192me = "jj2name";193}194}195196static class oranges {197oranges() {198}199}200}201202203204EOF205}206207# drive jdb by sending cmds to it and examining its output208dojdbCmds()209{210setBkpts @1211runToBkpt @1212213# verify that it works ok when arg types are the same as214# the param types215cmd eval "$classname.ffboolean($classname.jjboolean)"216cmd eval "$classname.ffbyte($classname.jjbyte)"217cmd eval "$classname.ffchar($classname.jjchar)"218cmd eval "$classname.ffdouble($classname.jjdouble)"219cmd eval "$classname.fffloat($classname.jjfloat)"220cmd eval "$classname.ffint($classname.jjint)"221cmd eval "$classname.fflong($classname.jjlong)"222cmd eval "$classname.ffshort($classname.jjshort)"223cmd eval "$classname.ffintArray($classname.jjintArray)"224cmd eval "$classname.ffjj1($classname.myjj1)"225226# Provide a visual break in the output227cmd print 1228229# Verify mixing primitive types works ok230# These should work even though the arg types are231# not the same because there is only one232# method with each name.233cmd eval "$classname.ffbyte($classname.jjint)"234cmd eval "$classname.ffchar($classname.jjdouble)"235cmd eval "$classname.ffdouble($classname.jjfloat)"236cmd eval "$classname.fffloat($classname.jjshort)"237cmd eval "$classname.ffint($classname.jjlong)"238cmd eval "$classname.fflong($classname.jjchar)"239cmd eval "$classname.ffshort($classname.jjbyte)"240241cmd print 1242243# Verify that passing a subclass object works244cmd eval "$classname.ffjj1($classname.myjj2)"245cmd eval "$classname.myjj1.toString().equals("jj1name")"246247cmd print 1248249# Overloaded methods. These should pass250# because there is an exact match.251cmd eval "$classname.ffoverload($classname.jjboolean)"252253cmd eval "$classname.ffoverload($classname.jjchar)"254cmd eval "$classname.ffoverload($classname.jjdouble)"255cmd eval "$classname.ffoverload($classname.jjfloat)"256cmd eval "$classname.ffoverload($classname.jjlong)"257cmd eval "$classname.ffoverload($classname.jjshort)"258cmd eval "$classname.ffoverload($classname.jjintArray)"259cmd eval "$classname.ffoverload($classname.myjj1)"260cmd eval "$classname.ffoverload($classname.myjj2)"261jdbFailIfPresent "Arguments match no method"262263cmd print 1264cmd print '"These should fail with msg Arguments match multiple methods"'265266# These overload calls should fail because ther267# isn't an exact match and jdb isn't smart enough268# to figure out which of several possibilities269# should be called270cmd eval "$classname.ffoverload($classname.jjbyte)"271jdbFailIfNotPresent "Arguments match multiple methods" 3272273cmd eval "$classname.ffoverload($classname.jjint)"274jdbFailIfNotPresent "Arguments match multiple methods" 3275276cmd print 1277cmd print '"These should fail with InvalidTypeExceptions"'278279cmd eval "$classname.ffboolean($classname.jjbyte)"280jdbFailIfNotPresent "InvalidTypeException" 3281282cmd eval "$classname.ffintArray($classname.jjint)"283jdbFailIfNotPresent "InvalidTypeException" 3284285cmd eval "$classname.ffintArray($classname.jjfloatArray)"286jdbFailIfNotPresent "InvalidTypeException" 3287288cmd eval "$classname.ffjj2($classname.myjj1)"289jdbFailIfNotPresent "InvalidTypeException" 3290291cmd eval "$classname.ffjj2($classname.myoranges)"292jdbFailIfNotPresent "InvalidTypeException" 3293294cmd quit295}296297298mysetup()299{300if [ -z "$TESTSRC" ] ; then301TESTSRC=.302fi303304for ii in . $TESTSRC $TESTSRC/.. ; do305if [ -r "$ii/ShellScaffold.sh" ] ; then306. $ii/ShellScaffold.sh307break308fi309done310}311312# You could replace this next line with the contents313# of ShellScaffold.sh and this script will run just the same.314mysetup315316runit317pass318319320