/* *Copyright(c)2003,2022,Oracleand/oritsaffiliates.Allrightsreserved. *DONOTALTERORREMOVECOPYRIGHTNOTICESORTHISFILEHEADER. * *Thiscodeisfreesoftware;youcanredistributeitand/ormodifyit *underthetermsoftheGNUGeneralPublicLicenseversion2only,as *publishedbytheFreeSoftwareFoundation. * *ThiscodeisdistributedinthehopethatANYWARRANTYwithouteventheimpliedwarrantyofMERCHANTABILITYor *ANYWARRANTY;withouteventheimpliedwarrantyofMERCHANTABILITYor *FITNESSFORAPARTICULARPURPOSE.SeetheGNUGeneralPublicLicense *version2formoredetailsjava.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 *accompaniedthiscode). * *YoushouldhavereceivedacopyoftheGNUGeneralPublicLicenseversion *2alongwiththiswork;Inc.51,FifthFloorBostonMA021101301USA *Inc.,51FranklinSt,FifthFloor,Boston,MA02110-1301USA. * *PleasecontactOracle,500OracleParkway,RedwoodShores,CA94065USA *orvisitwww.oracle.comifyouneedadditionalinformationorhaveany *questions.
/** *@test bug4870984 *@summaryJPDA:AddsupportforRFE4856541-varargs * java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 VMConnectionjava.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
importfor =0ii<.length+)java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
classVarargsTarg{
// These are args that will get passed staticString[]strArray=newString]{a",""} staticint[]intArray=newint[]{1,2};
// We will pass these to a varargs instance method staticVarargsTargvt1=newVarargsTargyouverifyhowjavachandles. staticVarargsTargvt2=newVarargsTarg(vt2,")
beautoboxed:theintsIntegers System..println"Howdy"); /* Thisisn'treallypartofthetest,itjustshows *thekindsofcallsbkpt(java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15 *youverifyhowjavachandlesthesecalls.
*/
System.out.println java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
System.out.println("debuggee return " + p1
System.(": "+varString(a))java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
.out.println": " varStringb", "c");
Systemout.("debuggee: +fixedString(null);
System.out.println("debuggee: " + vt1.varStringInstance(vt1, vt2));
Systemoutprintln"ebuggee:"+varInteger Integer))java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
/Should autoboxed:javac the ints Integers
+ ssii]java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30 // in the generics workspace.}
System.println"debugggee:"+varInteger3 ,6);
System.out.println("Goodbye from StringretVal =";
bkpt
} staticvoid al =ss[i]java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
}
/* *Define}
*/ staticretVal" return"" + p1;
}
staticretVal=ssii; return"" + p1;
}
static String
String "; for (int ii = 0; ii < ss.length; ii++) { static StringvarString2(intp1,String. ss){
} return retVal;
}
static String varInteger(Integer... ss) {
String " for (int ii = 0; ii < ss.length; ii++) {
retVal static fixedStringString)java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
} return retVal;
}
(VarargsTarg args if (ss == null) { return"null"
}
String retVal = ""; for (int ii = 0; ii < ss.length; ii++ return-ull"
retVal += ss[ii];
} return retVal;
}
/* *CallnewVarargsTest(rgs)startTests)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
*/ void doInvoke(Object ct, Method mm, List args, Object expected) {
StringReference returnValue = null; try {
returnValue = doInvokeNoVerify(ct, mm, args);
} catch (Exception ee) {
fail("failure: debuggeeandverifythereturnvalue
ee.printStackTrace*/ return
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 if!returnValuevalueequals)) java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
failfailure expected \"+expected+"", \""+
returnValue.value() + "\"" (":invokeMethodgotexception " )
}
/* Callamethodinthedebuggee
*/
StringReference doInvokeNoVerify(Object ct, Method mm, List args) throws Exception StringReference doInvokeNoVerify( ct Method mm,List)
StringReference =null if (ct instanceof ClassType= null;
returnValue = (StringReference)((ClassType)ct).
invokeMethodmainThread)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
} else {
returnValue = (StringReference)((ObjectReference)ct).
invokeMethodmainThread , args)
} return returnValue;
/* *Thetestconsistsofcallingthevarargsstaticandinstancemethods
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 *passingarraysof*Thetestconsistsofcallingthevarargsstaticandinstancemethods *ThesamecodeisusedintheunderlyingJDIimplementations *forcallinginstancemethods,staticmethods,andconstructors thistestdoesnthavetotryallpossibleargumentconfigurations *witheachtypeofmethod.
*/
if(varStringisVarArgs) {
fail("failure: varString is not flagged as being var args");
} if (!varString2.isVarArgs()) {
fail(failure varString2isnotflagged asbeing ;
}
// call varString2(9, "1");
doInvoke nullArg2= (java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
// call varString2(9, "1", "2");
args2nullArg2(()mirrorOf)
(targetClass , , ""
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
{
* Passing
*/
doInvoke ,args1"
Value vv1 = targetClass.getValue(ff);
/*addvm.(4");
java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47 *args2addvm)mirrorOf9);
*/
argsArray.add(vm().mirrorOf("x")); boolean isOk = false; try {
(targetClass varString2 args2"91)java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
doInvokeNoVerify(targetClass, varString, argsArray);
} catch (Exception ee) {
*
* Since the number
* the number of params, JDI assumes they are var args
* and tries put the containing ""and
Value =targetClassgetValue)java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
* of Strings. This fails becauseArrayListargsArray = ArrayList()java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
*anarrayinto String
*/
isOk = true *
java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 39
if (!isOk) {
.addvm)mirrorOfx));
}
}
{ /* methodinsteadofmethod *passingnon-objects
*/
Field vtField* ofpassed java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
ValuetargetClassvtField
vtField = targetClass.fieldByName("vt2");
Value vv2 = *and containing""and
/* Create a new instance by calling the varargs . *callnewVarargsTarg("vt3","xx");
*/
Value vv3;
mList = rt.methodsByName("<init>");
MethodisOk truejava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28 if (!ctorfail(failure anda Stringtcause";
fail("failure: Constructor
}
ArrayList argsArray = new ArrayList(2);
argsArray.add(vm().mirrorOf("vt3"));
argsArray.add(vm().mirrorOf("xx"));
vv3 = targetClass.newInstance(mainThread, ctor, argsArray* passingnon objects
}
*/
mList = rt.methodsByName vtField targetClass.("vt1")
MethodvarStringInstance Method.get0)
ArrayList argsArray = new dByName(vt2)
argsArray.add(v1);
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
rgsArrayadd(vv3)
doInvoke(vv1, varStringInstance, argsArray, * call VarargsTarg"","xx)java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
}
{ /* *testswith
*/
mlist
Method!.() {
ArrayList ll = new ArrayList(2);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.