[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-2d-dev
Subject:    Re: RFR: 6521141: DebugGraphics NPE @ setFont(); [v5]
From:       Phil Race <prr () openjdk ! org>
Date:       2022-07-29 16:53:45
Message-ID: AIus88g7s308GZyyZqbVihnnW_0glFFsba_sNFQkBaw=.eb76407b-017a-4d3a-9105-bd9fbc7d11f8 () github ! com
[Download RAW message or body]

On Fri, 29 Jul 2022 14:24:34 GMT, Tejesh R <tr@openjdk.org> wrote:

> > `DebugGraphics` class has a Graphics instance which is been used in slowed down \
> > drawing. The `graphics` object is not initialized anywhere inside the class, \
> > where it is expected to set explicitly by the user. When the user doesn't set it \
> > and try to use the any mehtods like `drawing/setFont`, NPE is raised which is \
> > expected. The scenario is taken care by checking if the `graphics` object is null \
> > before using it inside the class, thus eliminating the NPE case.
> 
> Tejesh R has updated the pull request incrementally with one additional commit \
> since the last revision: 
> Fix: Java doc modified and Graphics contexts created in null case

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.

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

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic