Class OpenReflectException

All Implemented Interfaces:
OpenExceptionMeta, Serializable

public class OpenReflectException extends OpenException
Reflection Operation Exception (Unchecked) 反射操作异常(非受检)

Unchecked exception for reflection operations that wraps checked exceptions. Simplifies caller code by eliminating mandatory try-catch blocks.

用于反射操作的非受检异常,封装受检异常。 通过消除强制性的try-catch块来简化调用方代码。

Features | 主要功能:

  • Unchecked exception wrapper - 非受检异常包装
  • Target type and member tracking - 目标类型和成员追踪
  • Factory methods for common errors - 常见错误的工厂方法

Usage Examples | 使用示例:

// Create with factory method
throw OpenReflectException.fieldNotFound(User.class, "name");

// Create with details
throw new OpenReflectException(User.class, "getName", "invoke", "Method not accessible");

Security | 安全性:

  • Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
  • Null-safe: Yes (null target type is allowed) - 空值安全: 是(允许null目标类型)
Since:
JDK 25, opencode-base-reflect V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • OpenReflectException

      public OpenReflectException(String message)
      Creates an exception with message 创建带消息的异常
      Parameters:
      message - the error message | 错误消息
    • OpenReflectException

      public OpenReflectException(String message, Throwable cause)
      Creates an exception with message and cause 创建带消息和原因的异常
      Parameters:
      message - the error message | 错误消息
      cause - the cause | 原因
    • OpenReflectException

      public OpenReflectException(Class<?> targetType, String memberName, String operation, String message)
      Creates an exception with target, member, operation and message 创建带目标、成员、操作和消息的异常
      Parameters:
      targetType - the target type | 目标类型
      memberName - the member name | 成员名称
      operation - the operation type | 操作类型
      message - the error message | 错误消息
    • OpenReflectException

      public OpenReflectException(Class<?> targetType, String memberName, String operation, String message, Throwable cause)
      Creates an exception with target, member, operation, message and cause 创建带目标、成员、操作、消息和原因的异常
      Parameters:
      targetType - the target type | 目标类型
      memberName - the member name | 成员名称
      operation - the operation type | 操作类型
      message - the error message | 错误消息
      cause - the cause | 原因
  • Method Details

    • targetType

      public Class<?> targetType()
      Gets the target type 获取目标类型
      Returns:
      target type | 目标类型
    • memberName

      public String memberName()
      Gets the member name 获取成员名称
      Returns:
      member name | 成员名称
    • operation

      public String operation()
      Gets the operation type 获取操作类型
      Returns:
      operation type | 操作类型
    • fieldNotFound

      public static OpenReflectException fieldNotFound(Class<?> clazz, String fieldName)
      Creates a field not found exception 创建字段未找到异常
      Parameters:
      clazz - the class | 类
      fieldName - the field name | 字段名
      Returns:
      exception instance | 异常实例
    • fieldAccessFailed

      public static OpenReflectException fieldAccessFailed(Class<?> clazz, String fieldName, Throwable cause)
      Creates a field access failed exception 创建字段访问失败异常
      Parameters:
      clazz - the class | 类
      fieldName - the field name | 字段名
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • methodNotFound

      public static OpenReflectException methodNotFound(Class<?> clazz, String methodName, Class<?>[] paramTypes)
      Creates a method not found exception 创建方法未找到异常
      Parameters:
      clazz - the class | 类
      methodName - the method name | 方法名
      paramTypes - the parameter types | 参数类型
      Returns:
      exception instance | 异常实例
    • methodInvokeFailed

      public static OpenReflectException methodInvokeFailed(Class<?> clazz, String methodName, Throwable cause)
      Creates a method invoke failed exception 创建方法调用失败异常
      Parameters:
      clazz - the class | 类
      methodName - the method name | 方法名
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • constructorNotFound

      public static OpenReflectException constructorNotFound(Class<?> clazz, Class<?>[] paramTypes)
      Creates a constructor not found exception 创建构造器未找到异常
      Parameters:
      clazz - the class | 类
      paramTypes - the parameter types | 参数类型
      Returns:
      exception instance | 异常实例
    • instantiationFailed

      public static OpenReflectException instantiationFailed(Class<?> clazz, Throwable cause)
      Creates an instantiation failed exception 创建实例化失败异常
      Parameters:
      clazz - the class | 类
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • classNotFound

      public static OpenReflectException classNotFound(String className)
      Creates a class not found exception 创建类未找到异常
      Parameters:
      className - the class name | 类名
      Returns:
      exception instance | 异常实例
    • classLoadFailed

      public static OpenReflectException classLoadFailed(String className, Throwable cause)
      Creates a class load failed exception 创建类加载失败异常
      Parameters:
      className - the class name | 类名
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • typeCastFailed

      public static OpenReflectException typeCastFailed(Class<?> targetType, Object value)
      Creates a type cast failed exception 创建类型转换失败异常
      Parameters:
      targetType - the target type | 目标类型
      value - the value | 值
      Returns:
      exception instance | 异常实例
    • copyFailed

      public static OpenReflectException copyFailed(Class<?> sourceType, Class<?> targetType, Throwable cause)
      Creates a copy failed exception 创建复制失败异常
      Parameters:
      sourceType - the source type | 源类型
      targetType - the target type | 目标类型
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • proxyCreationFailed

      public static OpenReflectException proxyCreationFailed(Class<?> interfaceType, Throwable cause)
      Creates a proxy creation failed exception 创建代理创建失败异常
      Parameters:
      interfaceType - the interface type | 接口类型
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • annotationNotFound

      public static OpenReflectException annotationNotFound(Class<?> clazz, Class<?> annotationType)
      Creates an annotation not found exception 创建注解未找到异常
      Parameters:
      clazz - the class | 类
      annotationType - the annotation type | 注解类型
      Returns:
      exception instance | 异常实例
    • lambdaParseFailed

      public static OpenReflectException lambdaParseFailed(String reason)
      Creates a lambda parse failed exception 创建Lambda解析失败异常
      Parameters:
      reason - the reason | 原因
      Returns:
      exception instance | 异常实例
    • recordOperationFailed

      public static OpenReflectException recordOperationFailed(Class<?> recordClass, String operation, Throwable cause)
      Creates a record operation failed exception 创建Record操作失败异常
      Parameters:
      recordClass - the record class | Record类
      operation - the operation | 操作
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • illegalAccess

      public static OpenReflectException illegalAccess(Class<?> clazz, String memberName, Throwable cause)
      Creates an illegal access exception 创建非法访问异常
      Parameters:
      clazz - the class | 类
      memberName - the member name | 成员名
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例