Accessing classes

When we want to access the class objects during a stack walk, we have to specify the RETAIN_CLASS_REFERENCE option. Although the StackFrame interface defines the getClassName() method, that could be used to access a class of the name using the Class.forName() method, doing so would not guarantee that the class the StackFrame object refers to was loaded by the same class loader as the code calling Class.forName(). In some special cases, we could end up with two different classes of the same name loaded by two different class loaders.

When the option is not used during the creation of the StackWalker instance, the methods that otherwise return a class object will throw an UnsupportedOperationException exception. That way, getDeclaringClass() cannot be used on StackFrame and getCallerClass() on StackWalker.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset