Record Class ClassLoadTrace

java.lang.Object
java.lang.Record
cloud.opencode.base.classloader.diagnostic.ClassLoadTrace
Record Components:
className - the fully qualified class name | 完全限定类名
delegationChain - the ordered list of ClassLoader names consulted during loading | 加载期间按顺序咨询的 ClassLoader 名称列表
definingLoader - the name of the ClassLoader that defines the class, or "bootstrap" | 定义该类的 ClassLoader 名称,或 "bootstrap"
location - the resource URL where the class was found, or null if not found | 发现该类的资源 URL,如果未找到则为 null

public record ClassLoadTrace(String className, List<String> delegationChain, String definingLoader, String location) extends Record
Immutable trace of a class loading delegation chain 类加载委托链的不可变跟踪记录

Captures the full delegation path traversed when loading a class, showing which ClassLoaders were consulted and which one ultimately defined the class. This is invaluable for debugging ClassNotFoundException or unexpected class versions.

捕获加载类时遍历的完整委托路径,显示咨询了哪些 ClassLoader 以及最终由哪个定义了该类。 这对于调试 ClassNotFoundException 或意外的类版本非常有价值。

Features | 主要功能:

  • Records full delegation chain - 记录完整的委托链
  • Identifies the defining loader - 标识定义加载器
  • Captures resource location (URL) - 捕获资源位置 (URL)

Usage Examples | 使用示例:

ClassLoadTrace trace = ClassLoaderDiagnostics.traceClassLoading(
    "com.example.Foo", myClassLoader
);
System.out.println("Defined by: " + trace.definingLoader());

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是 (不可变记录)
Since:
JDK 25, opencode-base-classloader V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • ClassLoadTrace

      public ClassLoadTrace(String className, List<String> delegationChain, String definingLoader, String location)
      Compact constructor with validation and defensive copies 带验证和防御性拷贝的紧凑构造器
      Throws:
      NullPointerException - if className, delegationChain, or definingLoader is null | 当 className、delegationChain 或 definingLoader 为 null 时
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • className

      public String className()
      Returns the value of the className record component.
      Returns:
      the value of the className record component
    • delegationChain

      public List<String> delegationChain()
      Returns the value of the delegationChain record component.
      Returns:
      the value of the delegationChain record component
    • definingLoader

      public String definingLoader()
      Returns the value of the definingLoader record component.
      Returns:
      the value of the definingLoader record component
    • location

      public String location()
      Returns the value of the location record component.
      Returns:
      the value of the location record component