RFR: 6521141: DebugGraphics NPE @ setFont(); [v5]

Phil Race prr at openjdk.org
Mon Aug 1 17:41:05 UTC 2022


On Mon, 1 Aug 2022 06:17:33 GMT, Tejesh R <tr at openjdk.org> wrote:

>> src/java.desktop/share/classes/javax/swing/DebugGraphics.java line 87:
>> 
>>> 85:         //  directly.
>>> 86:         StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
>>> 87:         if ((graphics == null) && (walker.getCallerClass() != this.getClass())) {
>> 
>> I don't know if creating a StackWalker is expensive but I think it should be done only if graphics == null
>> 
>> Also the version of getInstance() being called here might throw SecurityException
>> https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/StackWalker.html#getInstance(java.lang.StackWalker.Option)
>> 
>> So you'll need to wrap it in a doPrivileged.
>
> @prrace Then I will proceed by removing Stackwalker and create a graphics instance only if its `null`.

No, because that won't work, or more precisely will be a waste of work.
See
DebugGraphics(Graphics graphics) {
this(); // << no-args constructor and graphics will still be null
this.graphics = null;
}

graphics will ALWAYS be null when you come via here which is exactly why we needed StackWalker

-------------

PR: https://git.openjdk.org/jdk/pull/9673



More information about the client-libs-dev mailing list