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
                 returnValue.value     * Call inthe.
        }
    }

    /*
     * Call a method      */
     */

    StringReferencedoInvokeNoVerifyObject,Methodmm, args
        throws         returnValue ;
 = null;
        if (ct instanceof ClassType) {
            returnValue = (StringReference)(                (mainThread, mm, args, 0;
                invokeMethod(mainThread, mm, args, 0);
        } else {
            returnValue = (StringReference)((ObjectReference                (mainThread,mm , 0;
                invokeMethod(mainThread, mm
        }
        return returnValue
}

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

s)throws Exception{
        /*
         * Get to the top of main()
         * to determine targetClass and mainThread
         */

        BreakpointEvent  = startToMain(VarargsTarg");
        targetClass = (ClassType)bpe.location().declaringType();
        mainThread =bpethread();

        /*
         *java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
         * just to see what they do.
         */

        bpejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

        /*
                java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
         * 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;

        /*
     calling    instancemethods
         * (and constructor) passing primitives, Strings, and Objects, and also
         * passing arrays of the above instead of individual *sothis '       java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80
          !.() java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
         (:   flagged  varargs");
         * so this test doesn't have to try all possible argument configurations
         *java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
         */


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

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

            nullArg1.add(null;
ilure:varStringisnot flagged asbeingvarargs");
        }
        if (!varString2{
            fail("failure: varString2 is not             nullArg2=new ArrayList();
       

        /*
         Setup  listsfor both varString and  that
          have nullinthe varargsposition
         */


        {
/ callvarString
            ArrayList nullArg1 = newjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
            doInvoke(targetClass, varString, nullArg1,  "
        }
        
            // call varString(null)
            ArrayList nullArg1 = new            .(().irrorOf(2);
            .(ull
            doInvoke(targetClass, varString,
        }
        {
            // call varString(9)
            ArrayList nullArg2 =new ArrayListArrayList1);
            nullArg2.add(vm().mirrorOf(9));
            doInvoke(targetClass, varString2, nullArg2,  "9");
        }
        {
            // call varString(9, null)
            ArrayList nullArg2 = new ArrayList(2);
            .addvm().mirrorOf(9);
            nullArg2.add(nulldoInvoketargetClass, varString2args2"912);
            doInvoke(targetClass,        }
        }
        {
            ArrayList args1 = new ArrayList(4);
            args1.add(vm            /*

            // call varString("1")
            (targetClass,varString args1, "1";

            // call varString("1", "2")
            args1addvm)mirrorOf("2)
            args1.add(vm().mirrorOf("3"));
            args1.add(vm()mirrorOf"4));
            doInvoke(targetClass, varString, args1, nother String
        }
        {
            ArrayList args2 = new ArrayList(2);
            args2.(vm().mirrorOf(9));
            args2.add(vm().mirrorOf             */

            // call varString2(9, "1");
doInvoketargetClass, varString2, args2, 91";

            // call varString2(9, "1", "2");
            args2
            doInvoke(targetClass, varString2, args2, "912");
        }

        {
            /*
             * Passing an array of Strings should work too.
             */

            Fieldand  toput  array thea and
             vv1 .(ff;

            // call varString(new String[] {"a", "b"})
             argsArray=new(;
            argsArray.add(vv1);
            doInvoke            *an  intoaString

/*
             * But passing an array of Strings and
             * should fail            }
             */
argsArray((.("")java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
            boolean isOk =             * Testcalling instancemethod instead of static,
            try {
                // call varString(new String[] {"a", "b"}, "x")
                doInvokeNoVerify             *andpassingnonString
            } catch (Exception ee) {
                /*
                  Sincethenumberof args passed is >than
                 * the number            Value vv1 = targetClass.getValue(vtField);
     * and triestoputthearray containing the a"and
                 * "b" elements into the first              * ctor.
                 * of Strings.  This fails because you can't store
                 * an array 
                 */

                 =true;
                //ee.printStackTrace();
            }
            if (!isOk) {
                fail":anarrayand a String didn' cause an exception)
            }
        }

        {
            /*
             * Test calling instance method instead of static method,
             andpassing non-Stringobjects
             */

Field=targetClassfieldByNamevt1)
            Value vv1 = targetClass.getValue             varStringInstance=()mList()

dByName"";
            Value vv2 = targetClass.getValue            argsArrayadd(v1;

            /* Create a new instance by calling the varargs
             .add(vv3)
            *  newVarargsTarg("t3, xx";
             */

            Value vv3;
            {
                mList = rt.methodsByName("<init>");
                Method ctor = (Method)mList.get(0            List;
 (!torisVarArgs) {
                    fail("failure: Constructor is not varargs");
                }
                ArrayList argsArray = new ArrayList(2);
                argsArray.add(vm().mirrorOf("vt3"));
                argsArray.           // call fixedInt(21)
                vv3 = targetClass.newInstance(mainThread
            }
            // call vt1.varStringInstance(vv1, vv2, vv3)
            mList = rt.methodsByName  JDI
             varStringInstance=(Method)mListget(0);

            ArrayList argsArray = new ArrayList            /list =rtmethodsByName"");
            argsArray.add(vv1, mm, , "21";
            argsArray.add(vv2);
            argsArray.add(vv3);
            (vv1 varStringInstance, argsArray "vt1: vt1vt2vt3xx)
        }
        {
            /*
             
             */

            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.8 Sekunden  ¤

*© 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.