当前位置: 首页>>代码示例>>Java>>正文


Java InvocationTargetException类代码示例

本文整理汇总了Java中java.lang.reflect.InvocationTargetException的典型用法代码示例。如果您正苦于以下问题:Java InvocationTargetException类的具体用法?Java InvocationTargetException怎么用?Java InvocationTargetException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


InvocationTargetException类属于java.lang.reflect包,在下文中一共展示了InvocationTargetException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendObjective

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
private void sendObjective(Objective obj, ObjectiveMode mode) {
    try {
        Object objHandle = NMS.getHandle(obj);

        Object packetObj = NMS.PACKET_OBJ.newInstance(
                objHandle,
                mode.ordinal()
        );

        NMS.sendPacket(packetObj, player);
    } catch(InstantiationException | IllegalAccessException
            | InvocationTargetException | NoSuchMethodException e) {

        LOGGER.error("Error while creating and sending objective packet. (Unsupported Minecraft version?)", e);
    }
}
 
开发者ID:MinusKube,项目名称:Netherboard,代码行数:17,代码来源:BPlayerBoard.java

示例2: newFactory

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
/**
 * Retrieves a new HsqlSocketFactory whose class
 * is determined by the implClass argument. The basic contract here
 * is that implementations constructed by this method should return
 * true upon calling isSecure() iff they actually create secure sockets.
 * There is no way to guarantee this directly here, so it is simply
 * trusted that an  implementation is secure if it returns true
 * for calls to isSecure();
 *
 * @return a new secure socket factory
 * @param implClass the fully qaulified name of the desired
 *      class to construct
 * @throws Exception if a new secure socket factory cannot
 *      be constructed
 */
private static HsqlSocketFactory newFactory(String implClass)
throws Exception {

    Class       clazz;
    Constructor ctor;
    Class[]     ctorParm;
    Object[]    ctorArg;
    Object      factory;

    clazz    = Class.forName(implClass);
    ctorParm = new Class[0];

    // protected constructor
    ctor    = clazz.getDeclaredConstructor(ctorParm);
    ctorArg = new Object[0];

    try {
        factory = ctor.newInstance(ctorArg);
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();

        throw (t instanceof Exception) ? ((Exception) t)
                                       : new RuntimeException(
                                           t.toString());
    }

    return (HsqlSocketFactory) factory;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:44,代码来源:HsqlSocketFactory.java

示例3: processSignJellyBeans

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
private String processSignJellyBeans(PrivateKey privkey, byte[] data) {
    try {
        Method getKey = privkey.getClass().getSuperclass().getDeclaredMethod("getOpenSSLKey");
        getKey.setAccessible(true);
        // Real object type is OpenSSLKey
        Object opensslkey = getKey.invoke(privkey);
        getKey.setAccessible(false);
        Method getPkeyContext = opensslkey.getClass().getDeclaredMethod("getPkeyContext");
        // integer pointer to EVP_pkey
        getPkeyContext.setAccessible(true);
        int pkey = (Integer) getPkeyContext.invoke(opensslkey);
        getPkeyContext.setAccessible(false);
        // 112 with TLS 1.2 (172 back with 4.3), 36 with TLS 1.0
        byte[] signed_bytes = NativeUtils.rsasign(data, pkey);
        return Base64.encodeToString(signed_bytes, Base64.NO_WRAP);
    } catch (NoSuchMethodException | InvalidKeyException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
        VpnStatus.logError(R.string.error_rsa_sign, e.getClass().toString(), e.getLocalizedMessage());
        return null;
    }
}
 
开发者ID:akashdeepsingh9988,项目名称:Cybernet-VPN,代码行数:21,代码来源:VpnProfile.java

示例4: testBasicDenyParentAssocNode

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
public void testBasicDenyParentAssocNode() throws Exception
{
    runAs("andy");

    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("testOneChildAssociationRef", new Class[] { ChildAssociationRef.class });

    AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_PARENT.0.sys:base.Read")));

    proxyFactory.setTargetSource(new SingletonTargetSource(o));

    Object proxy = proxyFactory.getProxy();

    try
    {
        method.invoke(proxy, new Object[] { nodeService.getPrimaryParent(systemNodeRef) });
        assertNotNull(null);
    }
    catch (InvocationTargetException e)
    {

    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:27,代码来源:ACLEntryVoterTest.java

示例5: getAttributes

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
/**
 * Maps object attributes.
 * @param type the class to reflect.
 * @param object the instance to address.
 * @param <T> the class to reflect.
 * @return the attributes mapping.
 * @throws IntrospectionException when errors in reflection.
 * @throws InvocationTargetException when errors in reflection.
 * @throws IllegalAccessException when errors in reflection.
 */
public static <T> Map<String,Object> getAttributes(Class<T> type, T object)
    throws IntrospectionException, InvocationTargetException, IllegalAccessException {
  Map<String,Object> propsmap = new HashMap<>();
  final BeanInfo beanInfo = Introspector.getBeanInfo(type);
  final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
  for (PropertyDescriptor pd : propertyDescriptors) {
    if (pd.getName().equals("class")) continue;
    final Method getter = pd.getReadMethod();
    if (getter != null) {
      final String attrname = pd.getName();
      final Object attrvalue = getter.invoke(object);
      propsmap.put(attrname, attrvalue);
    }
  }
  return propsmap;
}
 
开发者ID:braineering,项目名称:ares,代码行数:27,代码来源:ReflectionManager.java

示例6: testPrivateMethodInOpenedPackage

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
/**
 * Invoke a private method on a public class in an open package
 */
public void testPrivateMethodInOpenedPackage() throws Exception {
    Method m = Unsafe.class.getDeclaredMethod("throwIllegalAccessError");
    assertFalse(m.canAccess(null));

    try {
        m.invoke(null);
        assertTrue(false);
    } catch (IllegalAccessException expected) { }

    assertTrue(m.trySetAccessible());
    assertTrue(m.canAccess(null));
    try {
        m.invoke(null);
        assertTrue(false);
    } catch (InvocationTargetException e) {
        // thrown by throwIllegalAccessError
        assertTrue(e.getCause() instanceof IllegalAccessError);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:TrySetAccessibleTest.java

示例7: currentStackFrameChanged

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
private void currentStackFrameChanged(CallStackFrame csf) {
    if (csf != null && csf.getClassName().startsWith(JSUtils.NASHORN_SCRIPT)) {
        JPDAThread thread = csf.getThread();
        suspendedNashornThread = new WeakReference<>(thread);
        try {
            Object node = dvSupport.getClass().getMethod("get", JPDAThread.class).invoke(dvSupport, thread);
            boolean explicitCollaps;
            synchronized (this) {
                explicitCollaps = collapsedExplicitly.contains(node);
            }
            if (!explicitCollaps) {
                fireNodeExpanded(node);
            }
        } catch (IllegalAccessException | IllegalArgumentException |
                 InvocationTargetException | NoSuchMethodException |
                 SecurityException ex) {
            Exceptions.printStackTrace(ex);
        }
    } else {
        suspendedNashornThread = NO_THREAD;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:DebuggingJSTreeExpansionModelFilter.java

示例8: addAnnotation

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
/**
 * @param c
 * @param annotation
 * @author [email protected]
 * @see <a href="https://stackoverflow.com/a/30287201/7803527">Origin code on stackoverflow</a>
 * @see java.lang.Class
 * @see #createAnnotationFromMap(Class, Map)
 */
@SuppressWarnings("unchecked")
public static <T extends Annotation> void addAnnotation(Class<?> c, T annotation) {
  try {
    while (true) { // retry loop
      int classRedefinedCount = Class_classRedefinedCount.getInt(c);
      Object /* AnnotationData */ annotationData = Class_annotationData.invoke(c);
      // null or stale annotationData -> optimistically create new instance
      Object newAnnotationData = changeClassAnnotationData(c, annotationData, (Class<T>) annotation.annotationType(),
          annotation, classRedefinedCount, true).getLeft();
      // try to install it
      if ((boolean) Atomic_casAnnotationData.invoke(Atomic_class, c, annotationData, newAnnotationData)) {
        // successfully installed new AnnotationData
        break;
      }
    }
  } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
    throw new IllegalStateException(e);
  }
}
 
开发者ID:XDean,项目名称:Java-EX,代码行数:28,代码来源:AnnotationUtil.java

示例9: getByLocator

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
@Override
    public By getByLocator() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {

        By byLocator = null;
//        Class<By> cls = (Class<By>) Class.forName("org.openqa.selenium.By");
//        Method m = cls.getMethod(this.typeOfLocator, String[].class);
//        String[] params = {this.attributeValue};

        if(this.typeOfLocator.equals("id")){
            byLocator =  By.id(this.attributeValue);
        }else if(this.typeOfLocator.equals("css")){
            byLocator =  By.cssSelector(this.attributeValue);
        }

//        return (By) m.invoke(null, (Object) params);
        return byLocator;
    }
 
开发者ID:AshokKumarMelarkot,项目名称:msa-cucumber-appium,代码行数:18,代码来源:Locator.java

示例10: structuralPropertyNamesOf

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
private static List<String> structuralPropertyNamesOf(final List<Class<? extends ASTNode>> nodes) {
    final List<String> names = new ArrayList<>();
    for (final Class<? extends ASTNode> node : nodes) {
        try {
            final Method m = node.getDeclaredMethod("propertyDescriptors", int.class);
            final List l = (List) m.invoke(null, AST.JLS8);
            for (final Object o : l) {
                final StructuralPropertyDescriptor d = (StructuralPropertyDescriptor) o;
                names.add(d.getId());
            }
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
            throw new RuntimeException("unexpected exception", ex);
        }
    }
    return names;
}
 
开发者ID:bblfsh,项目名称:java-driver,代码行数:17,代码来源:GoGen.java

示例11: eInvoke

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException {
	switch (operationID) {
		case ImPackage.STRING_LITERAL_FOR_STE___GET_VALUE_AS_STRING:
			return getValueAsString();
	}
	return super.eInvoke(operationID, arguments);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:14,代码来源:StringLiteralForSTEImpl.java

示例12: incDec

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private void incDec(final Adventure adv, final Class clazz, final String getMethod, final String setMethod, final Integer maxValue, final Object this_, boolean increase)
		throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
	Method mGetMethod;
	Method mSetMethod;
	Object instance;

	if (adv != null) {
		mGetMethod = clazz.getMethod(getMethod);
		mSetMethod = clazz.getMethod(setMethod, int.class);
		instance = adv;
	} else {
		mGetMethod = this_.getClass().getMethod(getMethod);
		mSetMethod = this_.getClass().getMethod(setMethod, int.class);
		instance = this_;
	}

	if (increase)
		mSetMethod.invoke(instance, Math.min(((Integer) mGetMethod.invoke(instance)) + 1, maxValue));
	else
		mSetMethod.invoke(instance, Math.max(((Integer) mGetMethod.invoke(instance)) - 1, 0));
}
 
开发者ID:joaomneto,项目名称:TitanCompanion,代码行数:23,代码来源:AdventureFragment.java

示例13: requestPermissions

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
/**
 * Requests "dangerous" permissions for the application at runtime. This is a helper method
 * alternative to cordovaInterface.requestPermissions() that does not require the project to be
 * built with cordova-android 5.0.0+
 *
 * @param plugin        The plugin the permissions are being requested for
 * @param requestCode   A requestCode to be passed to the plugin's onRequestPermissionResult()
 *                      along with the result of the permissions request
 * @param permissions   The permissions to be requested
 */
public static void requestPermissions(CordovaPlugin plugin, int requestCode, String[] permissions) {
    try {
        Method requestPermission = CordovaInterface.class.getDeclaredMethod(
                "requestPermissions", CordovaPlugin.class, int.class, String[].class);

        // If there is no exception, then this is cordova-android 5.0.0+
        requestPermission.invoke(plugin.cordova, plugin, requestCode, permissions);
    } catch (NoSuchMethodException noSuchMethodException) {
        // cordova-android version is less than 5.0.0, so permission is implicitly granted
        LOG.d(LOG_TAG, "No need to request permissions " + Arrays.toString(permissions));

        // Notify the plugin that all were granted by using more reflection
        deliverPermissionResult(plugin, requestCode, permissions);
    } catch (IllegalAccessException illegalAccessException) {
        // Should never be caught; this is a public method
        LOG.e(LOG_TAG, "IllegalAccessException when requesting permissions " + Arrays.toString(permissions), illegalAccessException);
    } catch(InvocationTargetException invocationTargetException) {
        // This method does not throw any exceptions, so this should never be caught
        LOG.e(LOG_TAG, "invocationTargetException when requesting permissions " + Arrays.toString(permissions), invocationTargetException);
    }
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:32,代码来源:PermissionHelper.java

示例14: run

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
private static <T> CompletableFuture<T> run(ThriftCall<T> call) {
    ThriftCompletableFuture<T> future = new ThriftCompletableFuture<>();
    try {
        call.apply(future);
    } catch (Exception e) {
        final Throwable cause;
        if (e instanceof InvocationTargetException) {
            cause = MoreObjects.firstNonNull(e.getCause(), e);
        } else {
            cause = e;
        }
        CompletableFuture<T> failedFuture = new CompletableFuture<>();
        failedFuture.completeExceptionally(cause);
        return failedFuture;
    }
    return future;
}
 
开发者ID:line,项目名称:centraldogma,代码行数:18,代码来源:DefaultCentralDogma.java

示例15: setBlock

import java.lang.reflect.InvocationTargetException; //导入依赖的package包/类
@Override
public boolean setBlock(int x, int y, int z, Integer blockId, Integer meta) {
    int id = blockId == null ? 0 : blockId;
    int damage = meta == null ? 0 : meta;
    try {
        this.hasChanged = true;
        return this.sections[y >> 4].setBlock(x, y & 0x0f, z, id, damage);
    } catch (ChunkException e) {
        int Y = y >> 4;
        try {
            this.setInternalSection(Y, (ChunkSection) this.providerClass.getMethod("createChunkSection", int.class).invoke(this.providerClass, Y));
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e1) {
            Server.getInstance().getLogger().logException(e1);
        }
        return this.sections[y >> 4].setBlock(x, y & 0x0f, z, id, damage);
    }
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:18,代码来源:BaseChunk.java


注:本文中的java.lang.reflect.InvocationTargetException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。