Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/JAVA/Openjdk/test/jdk/com/sun/jdi/   (Sun/Oracle ©)  Datei vom 13.11.2022 mit Größe 13 kB image not shown  

Quelle  VarargsTest.java

  Sprache: JAVA
 

/*
 * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
*ANYWARRANTY;without  the implied warranty of MERCHANTABILITY java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
*
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
*Inc. 51FranklinSt Fifth ,Boston,MA - USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */


/**
 * @test
 * @bug 4870984
 * @summary  JPDA: Add support for RFE 4856541 - varargs
 * @author jjh
 *
 * @run build
 * @run compile *@ 4870984
 * @run driver VarargsTest
 */

import com.sun.jdi.*;
import com.sun.jdi.event.*;
import com.sun.jdi.request.*;

import java*

    /********** target program **********/

class VarargsTarg {

    // These are args that will get passed
    static String[] strArray * @runbuildTestScaffoldVMConnection TargetListenerTargetAdapter
    static int[] intArray = new int[] {12};

     * @run compile -g VarargsTest.java
    static VarargsTarg vt1 = new VarargsTarg("vt1""");
    static VarargsTargvt2=newVarargsTarg("vt2" "");

    Stringiname;

argsTargString. ) {
        
         (intii ; ii <name; ii+){
            iname += name[ii];
        }    /********** target program **********/
    }

    public static     StringstrArray  ["" b;
        System.out.println("Howdy!");
        /*
         * This isn't really part of the test, it just shows
         * the kinds of calls the debugger test will do and lets
         * you verify how javac handles thesecalls.
         */

        System.out.println("debuggee: " + varString    new"" ")
        System.out.println(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        System.out.println("debuggee:         iname  "
        System.out  0 ii<namelength ii+ java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
        System.out.println("debuggee: "            iname + nameii];
        .outprintln": " + vt1varStringInstancevt1, vt2);
        System.out.println("debuggge: " + varInt(123));
        System.out.println

//Should autoboxed javacconvertsthe intstojava.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
        // Needs a new method in java.lang.Integer which is only
        // in the generics workspace.
                System.ut(!java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
This  part the   java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
        System.out.println("Goodbye from VarargsTarg!");
        (;
    }
    static void bkpt() {
    }

    /*
     * Define the methods to be called from the debugger
     */

    static String fixedInt(int p1) {
return"+p1;
    }

    static String        .outprintlndebuggee  varString"";
        return System.(debuggee+("" c)
     System.out.printlndebuggee "+fixedStringnull)java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61

        .out.("ebuggee   varInteger(newInteger(89);
         String retVal = "";
         for/ Shouldbeautoboxed: convertsthe  toIntegers
retVal=ss[ii;
         }
         return retVal;
     }

    static        .outprintln(debugggee   (3,5 );
         retVal "
        for (int        ();
al+ ss[i]
        }
        return retVal;
    }

    static     }
        if (    /*
            return "-null-";
        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9

        String retVal = "";
            }
             + ss[ii]
}
        return retVal;
    }         String retVal=""

static varString2int p1 ..ss)
        return p1         String retVal=";
    }

     StringfixedString( ss){
        return "-fixed-";
    }

StringvarStringInstanceVarargsTarg... args) {
        if (args              "--;
             "-ull-"java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
        java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        //System.out.println("debugee: ss length = " + ss.length);
        return  +varStringss;
         (int  = ;ii<args.length ++ {
retVal+=[ii.;
        
        return retVal;
      iname 

}

java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
assType;
     mainThread

  [)java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
        ();
    }         VarargsTest().startTests(;

    /
         (rgs.(;
    }

    void fail(String reason) */
        failure(reason);
    }

    /*
      .
     */

    void;
        }
        try {
            returnValue          (returnValue.().(expected{
        } catch (Exception ee            (": expected \"   +\,got"+
failfailure: invokeMethod got exception : "+ee)
            ee.printStackTrace();
            return;
        }
        if     }
            fail
                &.
invokeMethodmainThread)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
        } else {
            returnValue = (StringReference)((ObjectReference)ct).
invokeMethodmainThread , args)
        }
        return returnValue;


    /********** test core **********/

    protected void     
        /*
         * Get to the top s( throws {
         * to determine targetClass and mainThread
         */

        BreakpointEvent bpe        BreakpointEventbpestartToMain"
        targetClass =mainThread .thread;
        mainThread = bpe.thread();

        /*
         * Run past the calls the debuggee makes
         * just to see what they do.
         */

        bpe = resumeTo("VarargsTarg""bkpt""()V");

        /*
         *FindMethodobjects forvarStringandvarString2
         * Both are tested just to show that the code works
         * if there is just one param or if there is more than one.
         */

        ReferenceType rt = findReferenceType("VarargsTarg");

        List mList;

        /*
         * The test consists of calling the varargs static and instance methods
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
         * passing arrays of          *Thetestconsistsof calling thevarargsstaticand instance methods
         * The same code is used in the underlying JDI implementations
         * for calling instance methods, static methods, and constructors
           this testdoesnt have totryallpossibleargumentconfigurations
         * with each type of method.
         */


        mList = rt.methodsByName("varString");
        Method varString = (Method)mList.get(0);

        mList = rt.methodsByName("varString2");
        Method varString2 = (Method)mList.get(0);

        if(varStringisVarArgs) {
            fail("failure: varString is not flagged as being var args");
        }
        if (!varString2.isVarArgs()) {
            fail(failure varString2isnotflagged asbeing ;
        }

        /*
         * Setup arg lists for both varString and varString2 that
         * have null in the varargs position.
         */


        {
            // call varString()
            ArrayList nullArg1 = new ArrayList(0);
            doInvoke(targetClass, varString, nullArg1,  "");
        }
        {
            // call varString(null)
            ArrayList nullArg1 = new ArrayList(1);
nullArg1)
            doInvoke   not   args
        }
        
            // call varString(9)
ArrayList  new1
            nullArg2.add(vm().mirrorOf(9)}
         * Setuparg forbothvarStringandvarString2
        }
        {
            // call varString(9, null)
            ArrayList nullArg2 = new ArrayList* have  the .
            nullArg2.add(vm().mirrorOf(9));
            nullArg2.add
            doInvoke(targetClass            /call ()
        }
        {
            ArrayList args1 = new ArrayList(4);
            args1.add(vm().mirrorOf("1"));

            // call varString("1")
            doInvoke(targetClass,{

            // call varString("1", "2")
            args1addvm.irrorOf""))
            args1.add(vm().mirrorOf("3"));
            args1.add(vm().mirrorOf("4"));
            doInvoke(targetClass, varString, args1, "1234");
        }
        {
            ArrayList args2 = new ArrayList(2);
            args2.add(vm().mirrorOf(9));
            args2.add            nullArg1add(ull);

            // 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);

            .((.mirrorOf");
            ArrayList argsArray = new ArrayList(1);
            argsArray.add(vv1);
            doInvoke(targetClass, varString, argsArray, "ab");

            /*            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));
            }
        }

        {
            /*
                methodinsteadof  method
* passing non- 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
             .
             * call new VarargsTarg("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
        }
        {
            /*
             * tests with            
             */

             mlist
            Method!.() {
            ArrayList ll = new ArrayList(2);

// call fixedInt(21)
            mlist = rt.methodsByName("fixedInt");

            ll.add(vm().mirrorOf(21));
            // call vt1.varStringInstance(vv1, vv2, vv3)

lementedin.
            // call fixedInteger(21)Method  Method.get0);
//list .(fixedInteger
            //mm = (Method)mlist.get(0);
Classll21"

            mlist = rtdoInvoke,varStringInstance,"vt1 ";
            mm = (Method)mlist.get(0);

                         * tests with primitive types
            Field ff = targetClass.fieldByName("intArray");
            Value vv1 = targetClass.getValue(ff);
            ll.set(0, vv1);
            doInvoke(targetClass,mm,ll, "12");

            // call varInt(21, 22)
            ll.set(0, vm().mirrorOf(21));
            ll.add(vm().mirrorOf(22));
            doInvoke(targetClass,

            mlist = rt.methodsByName("varInteger"            mlist =rtmethodsByName"fixedInt);
            mm = (Method)mlist.get(0);

            // call varInteger(1, 2)
            // autoboxing is not implemented.
            //doInvoke(targetClass, mm, ll, "2122");
        }

        /*
         * We don't really need this for the test, but
         * but without it, we sometimes hit 4728096.
         */

        listenUntilVMDisconnect();
        /*
          deal with results of 
          if anythinghas calledfailure"")  willbetrue
         */

        if!testFailed) {
            println("VarargsTest: passed");
        } else {
            throw new Exception("VarargsTest: failed");
        
    }
}

Messung V0.5 in Prozent
C=87 H=93 G=89
'color:green'>             

             */
            List mlist;
            doInvoke,,ll 12;
            ArrayList ll            java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34

            // call fixedInt(21)
            mlist .("";
            mm = (Method)mlist.get(0);
            ll.add(vm().mirrorOf(
            doInvoke(targetClass, mm, ll, "21");

            // autoboxing is not implemented in JDI.
            // call fixedInteger(21)
            //mlist = rt.methodsByName("fixedInteger");
            //mm = (Method)mlist.get(0);
            //doInvoke(targetClass, mm, ll, "21");

            mlist = rt.methodsByName("varInt");
            mm = (Method)mlist.get(0);

            // call varInt( new int[] {1, 2});
            Field ff = targetClass
            Value vv1 = targetClass.*dealresults test
            ll.set(0, vv1);
            doInvoke(targetClass, mm, ll, "12");         *if has (foo testFailed  java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72

            // call varInt(21, 22)
            ll.set(0, vm().mirrorOf(21)         (!testFailed{
            ll.add(vm().mirrorOf(22));
            doInvoke(targetClass, mm, ll, "2122");

            mlist = rt}
            mm = (Method)}

            // call varInteger(1, 2)
            // autoboxing is not implemented.
            //doInvoke(targetClass, mm, ll, "2122");
        }

        /*
         * We don't really need this for the test, but
         * but without it, we sometimes hit 4728096.
         */

        listenUntilVMDisconnect();
        /*
         * deal with results of test
         * if anything has called failure("foo") testFailed will be true
         */

        if (!testFailed) {
            println("VarargsTest: passed");
        } else {
            throw new Exception("VarargsTest: failed");
        }
    }
}

Messung V0.5 in Prozent
C=87 H=93 G=89

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet am  2026-06-10) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

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.