當前位置: 首頁>>代碼示例>>Java>>正文


Java InvocationTargetException.getCause方法代碼示例

本文整理匯總了Java中java.lang.reflect.InvocationTargetException.getCause方法的典型用法代碼示例。如果您正苦於以下問題:Java InvocationTargetException.getCause方法的具體用法?Java InvocationTargetException.getCause怎麽用?Java InvocationTargetException.getCause使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.reflect.InvocationTargetException的用法示例。


在下文中一共展示了InvocationTargetException.getCause方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setDeclaredPropertyTest

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
public void setDeclaredPropertyTest(Map<String, Object> config, String schemaLocation, String typeName, Class<?> fieldType, String fieldName, String fieldGetter, Object value) throws Throwable {
    ClassLoader resultsClassLoader = schemaRule.generateAndCompile(schemaLocation, "com.example", config);

    Class<?> type = resultsClassLoader.loadClass("com.example." + typeName);
    Object instance = type.newInstance();

    try {
        type.getMethod("set", String.class, Object.class)
                .invoke(instance, fieldName, value);
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }

    assertThat("set for field " + fieldName + " of type " + fieldType + " works.",
            fieldType.cast(type.getMethod(fieldGetter)
                    .invoke(instance)),
            equalTo(value));

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:DynamicPropertiesIT.java

示例2: runTests

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
@Override
public void runTests() throws Exception {
    for (Method m : getClass().getDeclaredMethods()) {
        Annotation a = m.getAnnotation(Test.class);
        if (a != null) {
            for (FrameKind fk : FrameKind.values()) {
                for (OverviewKind ok : OverviewKind.values()) {
                    for (HtmlKind hk : HtmlKind.values()) {
                        try {
                            out.println("Running test " + m.getName() + " " + fk + " " + ok + " " + hk);
                            Path base = Paths.get(m.getName() + "_" + fk + "_" + ok + "_" + hk);
                            Files.createDirectories(base);
                            m.invoke(this, new Object[]{base, fk, ok, hk});
                        } catch (InvocationTargetException e) {
                            Throwable cause = e.getCause();
                            throw (cause instanceof Exception) ? ((Exception) cause) : e;
                        }
                        out.println();
                    }
                }
            }
        }
    }
    printSummary();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:TestFramesNoFrames.java

示例3: run

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
/** Run all test cases. */
void run() throws Exception {
    try {
        initTestClasses();

        for (Method m: getClass().getDeclaredMethods()) {
            Annotation a = m.getAnnotation(Test.class);
            if (a != null) {
                System.err.println(m.getName());
                try {
                    m.invoke(this, new Object[] { });
                } catch (InvocationTargetException e) {
                    Throwable cause = e.getCause();
                    throw (cause instanceof Exception) ? ((Exception) cause) : e;
                }
                System.err.println();
            }
        }

        if (errors > 0)
            throw new Exception(errors + " errors occurred");
    } finally {
        fm.close();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:ProfileOptionTest.java

示例4: invoke

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
public Object invoke(Object proxy, Method method, Object[] args)
    throws Throwable {
    if (method.getName().equals("setAutoCommit")) {
        setAutoCommit(((Boolean)args[0]).booleanValue());
    } else if (method.getName().equals("setTransactionIsolation")) {
        setTransactionIsolation(((Integer)args[0]).intValue());
    } else if (method.getName().equals("close")) {
        close();
    } else {
        try {
            return method.invoke(conn, args);
        }
        catch(InvocationTargetException ite) {
            throw (ite.getCause() != null ? ite.getCause() : ite);
        }
        
    }
    
    return null;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:AttributeRestoringConnectionInvocationHandler.java

示例5: throwRuntimeException

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
/**
 * Throw a {@link RuntimeException} with given message and cause lifted from an {@link
 * InvocationTargetException}. If the specified {@link InvocationTargetException} does not have a
 * cause, neither will the {@link RuntimeException}.
 */
private static void throwRuntimeException(String msg, InvocationTargetException e) {
  Throwable cause = e.getCause();
  if (cause != null) {
    throw new RuntimeException(msg + ": " + cause.getMessage(), cause);
  } else {
    throw new RuntimeException(msg + ": " + e.getMessage(), e);
  }
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:14,代碼來源:Bus.java

示例6: provision

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
/** Provisions a new T. */
private T provision(Errors errors, InternalContext context,
    ConstructionContext<T> constructionContext) throws ErrorsException {
  try {
    T t;
    try {
      Object[] parameters = SingleParameterInjector.getAll(errors, context, parameterInjectors);
      t = constructionProxy.newInstance(parameters);
      constructionContext.setProxyDelegates(t);
    } finally {
      constructionContext.finishConstruction();
    }

    // Store reference. If an injector re-enters this factory, they'll get the same reference.
    constructionContext.setCurrentReference(t);

    membersInjector.injectMembers(t, errors, context, false);
    membersInjector.notifyListeners(t, errors);

    return t;
  } catch (InvocationTargetException userException) {
    Throwable cause = userException.getCause() != null
        ? userException.getCause()
        : userException;
    throw errors.withSource(constructionProxy.getInjectionPoint())
        .errorInjectingConstructor(cause).toException();
  } finally {
    constructionContext.removeCurrentReference();
  }
}
 
開發者ID:maetrive,項目名稱:businessworks,代碼行數:31,代碼來源:ConstructorInjector.java

示例7: testInvokeAfterAppDelete

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
@Test
public void testInvokeAfterAppDelete() throws Exception {
  FirebaseApp app = FirebaseApp.initializeApp(firebaseOptions, "testInvokeAfterAppDelete");
  FirebaseAuth auth = FirebaseAuth.getInstance(app);
  assertNotNull(auth);
  app.delete();

  for (Method method : auth.getClass().getDeclaredMethods()) {
    int modifiers = method.getModifiers();
    if (!Modifier.isPublic(modifiers) || Modifier.isStatic(modifiers)) {
      continue;
    }

    List<Object> parameters = new ArrayList<>(method.getParameterTypes().length);
    for (Class<?> parameterType : method.getParameterTypes()) {
      parameters.add(Defaults.defaultValue(parameterType));
    }
    try {
      method.invoke(auth, parameters.toArray());
      fail("No error thrown when invoking auth after deleting app; method: " + method.getName());
    } catch (InvocationTargetException expected) {
      String message = "FirebaseAuth instance is no longer alive. This happens when "
          + "the parent FirebaseApp instance has been deleted.";
      Throwable cause = expected.getCause();
      assertTrue(cause instanceof IllegalStateException);
      assertEquals(message, cause.getMessage());
    }
  }
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:30,代碼來源:FirebaseAuthTest.java

示例8: callWithException

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
public T callWithException(Object receiver, Object... args) throws Throwable {
    try {
        return (T) this.method.invoke(receiver, args);
    } catch (InvocationTargetException e) {
        if (e.getCause() != null) {
            throw e.getCause();
        }
        throw e;
    }
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:11,代碼來源:RefMethod.java

示例9: invoke

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
private static Object invoke(Method m, Object obj, Object... args) throws Throwable {
    try {
        return m.invoke(obj, args);
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:GetSysPkgTest.java

示例10: colToChar_wrongArguments_throwsException

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
@Test(expected = IllegalArgumentException.class)
public void colToChar_wrongArguments_throwsException() throws Throwable {
    Method method = MoveTranslator.class.getDeclaredMethod("colToChar", int.class);
    method.setAccessible(true);

    try {
        method.invoke(null, 8);
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }
}
 
開發者ID:android-gamecollection,項目名稱:gamecollection,代碼行數:12,代碼來源:MoveTranslatorTest.java

示例11: invoke

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
private Object invoke(Object proxy, Method method, Object[] args, boolean retry) throws Throwable // NOSONAR
{
	String methodName = method.getName();
	Method pMethod = iface.getClass().getMethod(methodName, method.getParameterTypes());
	try
	{
		return pMethod.invoke(iface, args);
	}
	catch( InvocationTargetException e )
	{
		throw e.getCause();
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:14,代碼來源:ClientProxy.java

示例12: call

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
@Override
public Bundle call(Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
	String methodName = (String) args[args.length - 3];
	String arg = (String) args[args.length - 2];
	int methodType = getMethodType(methodName);
	if (METHOD_GET == methodType) {
		String presetValue = PRE_SET_VALUES.get(arg);
		if (presetValue != null) {
			Bundle res = new Bundle();
			res.putString("value", presetValue);
			return res;
		}
	}
	if (METHOD_PUT == methodType) {
		if (isSecureMethod(methodName)) {
			return null;
		}
	}
	try {
		return super.call(method, args);
	} catch (InvocationTargetException e) {
		if (e.getCause() instanceof SecurityException) {
			return null;
		}
		throw e;
	}
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:28,代碼來源:SettingsProviderHook.java

示例13: constructor_nullOffset

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
@Test(expectedExceptions=NullPointerException.class)
public void constructor_nullOffset() throws Throwable  {
    Constructor<OffsetTime> con = OffsetTime.class.getDeclaredConstructor(LocalTime.class, ZoneOffset.class);
    con.setAccessible(true);
    try {
        con.newInstance(LocalTime.of(11, 30, 0, 0), null);
    } catch (InvocationTargetException ex) {
        throw ex.getCause();
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:11,代碼來源:TCKOffsetTime.java

示例14: testURLClassLoader

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
public static void testURLClassLoader(String loaderName) throws Exception {
    System.err.println("---- test URLClassLoader name: " + loaderName);

    URL[] urls = new URL[] { CLASSES_DIR.toUri().toURL() };
    ClassLoader parent = ClassLoader.getSystemClassLoader();
    URLClassLoader loader = new URLClassLoader(loaderName, urls, parent);

    Class<?> c = Class.forName(THROW_EXCEPTION_CLASS, true, loader);
    Method method = c.getMethod("throwError");
    try {
        // invoke p.ThrowException::throwError
        method.invoke(null);
    } catch (InvocationTargetException x) {
        Throwable e = x.getCause();
        e.printStackTrace();

        StackTraceElement[] stes = e.getStackTrace();
        StackWalker.StackFrame[] frames = new StackWalker.StackFrame[] {
            Utils.makeStackFrame(c, "throwError", "ThrowException.java"),
            Utils.makeStackFrame(WithClassLoaderName.class, "testURLClassLoader",
                                 SRC_FILENAME),
            Utils.makeStackFrame(WithClassLoaderName.class, "main", SRC_FILENAME),
        };

        // p.ThrowException.throwError
        Utils.checkFrame(loaderName, frames[0], stes[0]);
        // skip reflection frames
        int i = 1;
        while (i < stes.length) {
            String cn = stes[i].getClassName();
            if (!cn.startsWith("java.lang.reflect.") &&
                !cn.startsWith("jdk.internal.reflect."))
                break;
            i++;
        }
        // WithClassLoaderName.testURLClassLoader
        Utils.checkFrame("app", frames[1], stes[i]);

        // WithClassLoaderName.main
        Utils.checkFrame("app", frames[2], stes[i+1]);

    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:44,代碼來源:WithClassLoaderName.java

示例15: onHandleError

import java.lang.reflect.InvocationTargetException; //導入方法依賴的package包/類
private Object onHandleError(InvocationTargetException e) throws Throwable {
	if (e.getCause() instanceof SecurityException) {
		return 0;
	}
	throw e.getCause();
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:7,代碼來源:PowerManagerStub.java


注:本文中的java.lang.reflect.InvocationTargetException.getCause方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。