Search in sources :

Example 16 with WrongMethodTypeException

use of java.lang.invoke.WrongMethodTypeException in project openj9 by eclipse.

the class AsTypeTest method doTestConvertBoolean.

public void doTestConvertBoolean(boolean v) throws Throwable {
    MethodHandle s;
    MethodHandle c;
    MethodType mt;
    Object o = Boolean.valueOf(v);
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(I)I", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)I", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, intFromBoolean(v), (int) c.invokeExact(this, (boolean) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)I", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, intFromBoolean(v), (int) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Z)Z", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)I", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, intFromBoolean(v), (int) c.invokeExact(this, (boolean) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)I", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, intFromBoolean(v), (int) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(J)J", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)J", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, longFromBoolean(v), (long) c.invokeExact(this, (boolean) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)J", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, longFromBoolean(v), (long) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Z)Z", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)J", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, longFromBoolean(v), (long) c.invokeExact(this, (boolean) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)J", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, longFromBoolean(v), (long) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(F)F", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)F", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, floatFromBoolean(v), (float) c.invokeExact(this, (boolean) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)F", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, floatFromBoolean(v), (float) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Z)Z", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)F", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, floatFromBoolean(v), (float) c.invokeExact(this, (boolean) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)F", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, floatFromBoolean(v), (float) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(D)D", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)D", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, doubleFromBoolean(v), (double) c.invokeExact(this, (boolean) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)D", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, doubleFromBoolean(v), (double) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Z)Z", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)D", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, doubleFromBoolean(v), (double) c.invokeExact(this, (boolean) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)D", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, doubleFromBoolean(v), (double) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(B)B", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)B", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, byteFromBoolean(v), (byte) c.invokeExact(this, (boolean) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)B", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, byteFromBoolean(v), (byte) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Z)Z", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)B", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, byteFromBoolean(v), (byte) c.invokeExact(this, (boolean) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)B", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, byteFromBoolean(v), (byte) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Z)Z", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)Z", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, v, (boolean) c.invokeExact(this, (boolean) v));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)Z", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, v, (boolean) c.invokeExact(this, (Object) o));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)Z", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, v, (boolean) c.invokeExact(this, (Object) o));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(C)C", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)C", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, charFromBoolean(v), (char) c.invokeExact(this, (boolean) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)C", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, charFromBoolean(v), (char) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Z)Z", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)C", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, charFromBoolean(v), (char) c.invokeExact(this, (boolean) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)C", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, charFromBoolean(v), (char) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(S)S", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)S", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, shortFromBoolean(v), (short) c.invokeExact(this, (boolean) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)S", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, shortFromBoolean(v), (short) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Z)Z", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)S", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, shortFromBoolean(v), (short) c.invokeExact(this, (boolean) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)S", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, shortFromBoolean(v), (short) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    /* test boxing */
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Z)Ljava/lang/Object;", null);
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (boolean) v, ((Boolean) (Object) c.invokeExact(this, (boolean) v)).booleanValue());
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Number;)Ljava/lang/Object;", null));
    try {
        c = cast(s, mt);
        noExceptionDuringCast(s, mt);
    } catch (WrongMethodTypeException t) {
        expectedExceptionDuringCast(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/String;)Ljava/lang/Object;", null));
    try {
        c = cast(s, mt);
        noExceptionDuringCast(s, mt);
    } catch (WrongMethodTypeException t) {
        expectedExceptionDuringCast(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
}
Also used : MethodType(java.lang.invoke.MethodType) WrongMethodTypeException(java.lang.invoke.WrongMethodTypeException) MethodHandle(java.lang.invoke.MethodHandle)

Example 17 with WrongMethodTypeException

use of java.lang.invoke.WrongMethodTypeException in project openj9 by eclipse.

the class AsTypeTest method doTestConvertByte.

public void doTestConvertByte(byte v) throws Throwable {
    MethodHandle s;
    MethodHandle c;
    MethodType mt;
    Object o = Byte.valueOf(v);
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(I)I", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)I", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (int) v, (int) c.invokeExact(this, (byte) v));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)I", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (int) v, (int) c.invokeExact(this, (Object) o));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(B)B", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)I", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (int) v, (int) c.invokeExact(this, (byte) v));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)I", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (int) v, (int) c.invokeExact(this, (Object) o));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(J)J", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)J", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (long) v, (long) c.invokeExact(this, (byte) v));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)J", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (long) v, (long) c.invokeExact(this, (Object) o));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(B)B", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)J", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (long) v, (long) c.invokeExact(this, (byte) v));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)J", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (long) v, (long) c.invokeExact(this, (Object) o));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(F)F", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)F", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (float) v, (float) c.invokeExact(this, (byte) v));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)F", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (float) v, (float) c.invokeExact(this, (Object) o));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(B)B", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)F", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (float) v, (float) c.invokeExact(this, (byte) v));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)F", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (float) v, (float) c.invokeExact(this, (Object) o));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(D)D", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)D", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (double) v, (double) c.invokeExact(this, (byte) v));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)D", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (double) v, (double) c.invokeExact(this, (Object) o));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(B)B", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)D", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (double) v, (double) c.invokeExact(this, (byte) v));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)D", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (double) v, (double) c.invokeExact(this, (Object) o));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(B)B", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)B", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (byte) v, (byte) c.invokeExact(this, (byte) v));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)B", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (byte) v, (byte) c.invokeExact(this, (Object) o));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)B", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (byte) v, (byte) c.invokeExact(this, (Object) o));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Z)Z", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)Z", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, castToBoolean(v), (boolean) c.invokeExact(this, (byte) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)Z", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, castToBoolean(v), (boolean) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(B)B", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)Z", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, castToBoolean(v), (boolean) c.invokeExact(this, (byte) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)Z", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, castToBoolean(v), (boolean) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(C)C", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)C", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, (char) v, (char) c.invokeExact(this, (byte) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)C", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (char) v, (char) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(B)B", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)C", null);
    try {
        c = cast(s, mt);
        if (explicit) {
            try {
                compare(s, mt, (char) v, (char) c.invokeExact(this, (byte) v));
            } catch (Throwable t) {
                exceptionDuringInvoke(s, mt, t);
            }
        } else {
            noExceptionDuringCast(s, mt);
        }
    } catch (WrongMethodTypeException t) {
        wrongMethodType(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)C", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (char) v, (char) c.invokeExact(this, (Object) o));
        } catch (ClassCastException t) {
            if (explicit) {
                exceptionDuringInvoke(s, mt, t);
            } else {
                expectedExceptionDuringInvoke(s, mt, t);
            }
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(S)S", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)S", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (short) v, (short) c.invokeExact(this, (byte) v));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)S", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (short) v, (short) c.invokeExact(this, (Object) o));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(B)B", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)S", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (short) v, (short) c.invokeExact(this, (byte) v));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;Ljava/lang/Object;)S", null);
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (short) v, (short) c.invokeExact(this, (Object) o));
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    /* test boxing */
    mt = MethodType.fromMethodDescriptorString("(Lcom/ibm/j9/jsr292/AsTypeTest;B)Ljava/lang/Object;", null);
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Object;)Ljava/lang/Object;", null));
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (byte) v, ((Byte) (Object) c.invokeExact(this, (byte) v)).byteValue());
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/Number;)Ljava/lang/Object;", null));
    try {
        c = cast(s, mt);
        try {
            compare(s, mt, (byte) v, ((Byte) (Object) c.invokeExact(this, (byte) v)).byteValue());
        } catch (Throwable t) {
            exceptionDuringInvoke(s, mt, t);
        }
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
    s = MethodHandles.lookup().findVirtual(AsTypeTest.class, "doTest", MethodType.fromMethodDescriptorString("(Ljava/lang/String;)Ljava/lang/Object;", null));
    try {
        c = cast(s, mt);
        noExceptionDuringCast(s, mt);
    } catch (WrongMethodTypeException t) {
        expectedExceptionDuringCast(s, mt, t);
    } catch (Throwable t) {
        exceptionDuringCast(s, mt, t);
    }
}
Also used : MethodType(java.lang.invoke.MethodType) WrongMethodTypeException(java.lang.invoke.WrongMethodTypeException) MethodHandle(java.lang.invoke.MethodHandle)

Example 18 with WrongMethodTypeException

use of java.lang.invoke.WrongMethodTypeException in project openj9 by eclipse.

the class MutableCallSiteTest method testBasicNegative_MutableCallSite.

/**
 * Basic negative test for MutableCallSite
 * @throws Throwable
 */
@Test(groups = { "level.extended" })
public void testBasicNegative_MutableCallSite() throws Throwable {
    MethodHandle mh = MethodHandles.lookup().findStatic(Math.class, "pow", MethodType.methodType(double.class, double.class, double.class));
    MutableCallSite mcs = new MutableCallSite(mh);
    boolean wmtThrown = false;
    try {
        String s = (String) mcs.dynamicInvoker().invokeExact(2, 3);
    } catch (WrongMethodTypeException e) {
        wmtThrown = true;
    }
    AssertJUnit.assertTrue(wmtThrown);
}
Also used : MutableCallSite(java.lang.invoke.MutableCallSite) WrongMethodTypeException(java.lang.invoke.WrongMethodTypeException) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Aggregations

MethodHandle (java.lang.invoke.MethodHandle)18 WrongMethodTypeException (java.lang.invoke.WrongMethodTypeException)18 MethodType (java.lang.invoke.MethodType)10 Test (org.testng.annotations.Test)6 ConstantCallSite (java.lang.invoke.ConstantCallSite)2 MutableCallSite (java.lang.invoke.MutableCallSite)1 SwitchPoint (java.lang.invoke.SwitchPoint)1 VolatileCallSite (java.lang.invoke.VolatileCallSite)1 Test (org.junit.Test)1