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 then the methods that otherwise return a class object will throw an UnsupportedOperationException exception. That way ...

Get Java 9: Building Robust Modular Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.