Proposed API for JEP 259: Stack-Walking API

David M. Lloyd david.lloyd at redhat.com
Sat Nov 14 15:01:55 UTC 2015


On 11/13/2015 06:07 PM, Brian Goetz wrote:
>> I considered Optional<Class<?>>. I believe it is rare to have a JNI
>> attached thread calling StackWalker::getCallerClass from native.  Most
>> common cases will find a caller class.   Returning an Optional will
>> force most common uses to handle the case if it’s absent.  It’s a
>> tradeoff that I think it’s better to return Thread.class for the JNI
>> attached thread calling getCallerClass in native which would rarely
>> happen.
>
> +1 on returning Thread.class in these cases.  Its a pragmatic compromise.

If you must return something non-null, maybe it'd be better to define a 
class just for that purpose, e.g.:

public final class StackWalker {

     ...

     public static final class NoCaller {
         private NoCaller() {}
     }
}

...and use NoCaller.class as your caller when there is none.  Bonus 
points if you can attach a protection domain with no permissions to that 
class.

-- 
- DML



More information about the core-libs-dev mailing list