java.lang.NoSuchFieldException.initCause()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(94)

本文整理了Java中java.lang.NoSuchFieldException.initCause()方法的一些代码示例,展示了NoSuchFieldException.initCause()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NoSuchFieldException.initCause()方法的具体详情如下:
包路径:java.lang.NoSuchFieldException
类名称:NoSuchFieldException
方法名:initCause

NoSuchFieldException.initCause介绍

暂无

代码示例

代码示例来源:origin: org.tinygroup/org.tinygroup.jspengine

/**
 * Retrieves a Field object for a given field on the specified class, having
 * set it accessible.
 *
 * @param cls       the Class on which the field is expected to be defined
 * @param fieldName the name of the field of interest
 * @throws NoSuchFieldException in case of any error retriving information about the field
 */
private static Field getField(Class cls, String fieldName) throws NoSuchFieldException {
  try {
    Field field = cls.getDeclaredField(fieldName);
    field.setAccessible(true);
    return field;
  } catch (NoSuchFieldException nsfe) {
    NoSuchFieldException e = new NoSuchFieldException(getMessage("classloaderutil.errorGettingField", fieldName));
    e.initCause(nsfe);
    throw e;
  }
}

代码示例来源:origin: org.bluestemsoftware.open.maven.tparty/jsp-2.1

/**
 *Retrieves a Field object for a given field on the specified class, having
 *set it accessible.
 *@param cls the Class on which the field is expected to be defined
 *@param fieldName the name of the field of interest
 *@throws NoSuchFieldException in case of any error retriving information about the field
 */
private static Field getField(Class cls, String fieldName) throws NoSuchFieldException {
  try {
    Field field = cls.getDeclaredField(fieldName);
    field.setAccessible(true);
    return field;
  } catch (NoSuchFieldException nsfe) {
    NoSuchFieldException e = new NoSuchFieldException(getMessage("classloaderutil.errorGettingField", fieldName));
    e.initCause(nsfe);
    throw e;
  }
}

代码示例来源:origin: net.sf.gluebooster.java.booster/gb-basic

exception.initCause(ex);
throw exception;

代码示例来源:origin: net.sf.gluebooster.java.booster/gb-basic

exception.initCause(ex);
throw exception;

代码示例来源:origin: jboss/jboss-javaee-specs

nsfe.initCause(t);
throw nsfe;

代码示例来源:origin: org.jboss.spec.javax.rmi/jboss-rmi-api_1.0_spec

nsfe.initCause(t);
throw nsfe;

代码示例来源:origin: org.compass-project/compass

err.initCause(e);
throw err;

代码示例来源:origin: xap/xap

public static IField getField(Field refField) throws NoSuchFieldException {
  Class declaringClass = refField.getDeclaringClass();
  String ownerClassName = declaringClass.getName();
  Field[] declaredFields = declaringClass.getDeclaredFields();
  int fieldIndex = 0;
  for (; fieldIndex < declaredFields.length; ++fieldIndex) {
    if (declaredFields[fieldIndex].equals(refField))
      break;
  }
  String className = ASMFactoryUtils.getCreateClassNamePrefix(ownerClassName) + CLASS_POSTFIX_NAME + fieldIndex;
  try {
    final ClassLoader targetClassLoader = ASMFactoryUtils.getClassTargetLoader(declaringClass);
    String classInternalName = className.replace('.', '/'); // build internal name for ASM
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, classInternalName,
        null, STANDARD_FIELD_INTERNAL_NAME, null);
    createConstructor(cw);
    createGetMethod(cw, declaringClass, refField);
    createSetMethod(cw, declaringClass, refField);
    cw.visitEnd();
    byte[] b = cw.toByteArray();
    Class definedClass = ASMFactoryUtils.defineClass(targetClassLoader, className, b);
    Constructor ctor = definedClass.getConstructor(Field.class);
    return (IField) ctor.newInstance(refField);
  } catch (Exception e) {
    NoSuchFieldException err = new NoSuchFieldException("Failed generating ASM field wrapper: " + e.toString());
    err.initCause(e);
    throw err;
  }
}

代码示例来源:origin: xap/xap

public static <T> IProperties<T> getProperties(Class declaringClass, Field[] fields)
    throws NoSuchFieldException {
  String ownerClassName = declaringClass.getName();
  String className = ASMFactoryUtils.getCreateClassNamePrefix(ownerClassName) + CLASS_PROPERTIES_POSTFIX_NAME;
  try {
    final ClassLoader targetClassLoader = ASMFactoryUtils.getClassTargetLoader(declaringClass);
    String classInternalName = className.replace('.', '/'); // build internal name for ASM
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC,
        classInternalName, null, "java/lang/Object", new String[]{IProperties.Helper.INTERNAL_NAME});
    createCtor(cw);
    String ownerClassNameInternalName = ownerClassName.replace('.', '/'); // build internal name for ASM
    createGetter(cw, ownerClassNameInternalName, fields);
    createSetter(cw, ownerClassNameInternalName, fields);
    cw.visitEnd();
    byte[] b = cw.toByteArray();
    Class<?> definedClass = ASMFactoryUtils.defineClass(targetClassLoader, className, b);
    return (IProperties<T>) definedClass.newInstance();
  } catch (Exception e) {
    NoSuchFieldException ex = new NoSuchFieldException("Can't create helper to: " + ownerClassName);
    ex.initCause(e);
    throw ex;
  }
}

相关文章