Search in sources :

Example 16 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project robovm by robovm.

the class ProxyTest method test_newProxyInstanceLjava_lang_ClassLoader$Ljava_lang_ClassLjava_lang_reflect_InvocationHandler.

/**
     * java.lang.reflect.Proxy#newProxyInstance(java.lang.ClassLoader,
     *        java.lang.Class[], java.lang.reflect.InvocationHandler)
     */
public void test_newProxyInstanceLjava_lang_ClassLoader$Ljava_lang_ClassLjava_lang_reflect_InvocationHandler() {
    Object p = Proxy.newProxyInstance(Support_Proxy_I1.class.getClassLoader(), new Class[] { Support_Proxy_I1.class, Support_Proxy_I2.class }, new InvocationHandler() {

        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            if (method.getName().equals("equals"))
                return new Boolean(proxy == args[0]);
            if (method.getName().equals("array"))
                return new int[] { (int) ((long[]) args[0])[1], -1 };
            if (method.getName().equals("string")) {
                if ("".equals(args[0]))
                    throw new Support_Proxy_SubException();
                if ("clone".equals(args[0]))
                    throw new Support_Proxy_ParentException();
                if ("error".equals(args[0]))
                    throw new ArrayStoreException();
                if ("any".equals(args[0]))
                    throw new IllegalAccessException();
            }
            return null;
        }
    });
    Support_Proxy_I1 proxy = (Support_Proxy_I1) p;
    assertTrue("Failed identity test ", proxy.equals(proxy));
    assertTrue("Failed not equals test ", !proxy.equals(""));
    int[] result = (int[]) proxy.array(new long[] { 100L, -200L });
    assertEquals("Failed primitive type conversion test ", -200, result[0]);
    boolean worked = false;
    try {
        proxy.string("");
    } catch (Support_Proxy_SubException e) {
        worked = true;
    } catch (Support_Proxy_ParentException e) {
    // is never thrown
    }
    assertTrue("Problem converting exception ", worked);
    worked = false;
    try {
        proxy.string("clone");
    } catch (Support_Proxy_ParentException e) {
    // is never thrown
    } catch (UndeclaredThrowableException e) {
        worked = true;
    }
    assertTrue("Problem converting exception ", worked);
    worked = false;
    try {
        proxy.string("error");
    } catch (Support_Proxy_ParentException e) {
    // is never thrown
    } catch (UndeclaredThrowableException e) {
    } catch (RuntimeException e) {
        worked = e.getClass() == ArrayStoreException.class;
    }
    assertTrue("Problem converting exception ", worked);
    worked = false;
    try {
        proxy.string("any");
    } catch (Support_Proxy_ParentException e) {
    // is never thrown
    } catch (UndeclaredThrowableException e) {
        worked = true;
    }
    assertTrue("Problem converting exception ", worked);
    Broken1 proxyObject = null;
    try {
        proxyObject = (Broken1) Proxy.newProxyInstance(Broken1.class.getClassLoader(), new Class[] { Broken1.class }, new Broken1Invoke());
    } catch (Throwable e) {
        fail("Failed to create proxy for class: " + Broken1.class + " - " + e);
    }
    float brokenResult = proxyObject.method(2.1f, 5.8f);
    assertTrue("Invalid invoke result", brokenResult == 5.8f);
}
Also used : Support_Proxy_SubException(tests.support.Support_Proxy_SubException) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) Support_Proxy_I1(tests.support.Support_Proxy_I1) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) Support_Proxy_ParentException(tests.support.Support_Proxy_ParentException)

Example 17 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project robovm by robovm.

the class UndeclaredThrowableExceptionTests method test_Constructor_Throwable.

/**
     * java.lang.reflect.UndeclaredThrowableException#UndeclaredThrowableException(java.lang.Throwable)
     */
public void test_Constructor_Throwable() throws Exception {
    UndeclaredThrowableException e = new UndeclaredThrowableException(throwable);
    assertEquals("Wrong cause returned", throwable, e.getCause());
    assertEquals("Wrong throwable returned", throwable, e.getUndeclaredThrowable());
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 18 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project robovm by robovm.

the class UndeclaredThrowableExceptionTests method test_Constructor_Throwable_String.

/**
     * java.lang.reflect.UndeclaredThrowableException#UndeclaredThrowableException(java.lang.Throwable, java.lang.String)
     */
public void test_Constructor_Throwable_String() throws Exception {
    UndeclaredThrowableException e = new UndeclaredThrowableException(throwable, msg);
    assertEquals("Wrong cause returned", throwable, e.getCause());
    assertEquals("Wrong throwable returned", throwable, e.getUndeclaredThrowable());
    assertEquals("Wrong message returned", msg, e.getMessage());
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 19 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project robovm by robovm.

the class UndeclaredThrowableExceptionTests method test_getCause.

/**
     * java.lang.reflect.UndeclaredThrowableException#getCause()
     */
public void test_getCause() throws Exception {
    UndeclaredThrowableException ute = new UndeclaredThrowableException(throwable);
    assertSame("Wrong cause returned", throwable, ute.getCause());
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 20 with UndeclaredThrowableException

use of java.lang.reflect.UndeclaredThrowableException in project robovm by robovm.

the class UndeclaredThrowableExceptionTests method test_getUndeclaredThrowable.

/**
     * java.lang.reflect.UndeclaredThrowableException#getUndeclaredThrowable()
     */
public void test_getUndeclaredThrowable() throws Exception {
    UndeclaredThrowableException ute = new UndeclaredThrowableException(throwable);
    assertSame("Wrong undeclared throwable returned", throwable, ute.getUndeclaredThrowable());
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Aggregations

UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)121 IOException (java.io.IOException)36 InvocationTargetException (java.lang.reflect.InvocationTargetException)14 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)14 Test (org.junit.Test)12 BufferedReader (java.io.BufferedReader)10 InputStreamReader (java.io.InputStreamReader)10 ServerSocket (java.net.ServerSocket)10 Socket (java.net.Socket)9 PollStatus (org.opennms.netmgt.poller.PollStatus)9 HashMap (java.util.HashMap)8 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)7 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)7 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)7 Method (java.lang.reflect.Method)6 AccessControlException (java.security.AccessControlException)6 SQLException (java.sql.SQLException)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)6