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

Tejesh R tr at openjdk.org
Fri Aug 5 09:32:06 UTC 2022


On Thu, 28 Jul 2022 18:11:02 GMT, Phil Race <prr at openjdk.org> wrote:

>> Tejesh R has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Removed whitespace error
>
> You wrote " The graphics object is not initialized anywhere inside the class, where it is expected to set explicitly by the user. "
> 
> which reads a bit like if the user does
> DebugGraphics dg = new DebugGraphics();
> they must then follow it up with
> dg.setGraphics(g);
> however there's no such method.
> 
> So any DebugGraphics created this way is useless.
> You can't use it for debugging 
> Making it protected won't prevent mis-use.
> Someone could subclass and provide a public no-args constructor and the problem will recur.
> 
> The javadoc for the class says :
> DebugGraphics objects are rarely created by hand
> 
> So likely no one should be doing this.
> 
> I'd just add javadoc saying "This constructor should not be called by applications, it
> is for internal use only. When called directly it will create an un-usable instance".
> 
> The only other thing I can think of is to try to figure out by using
> https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/StackWalker.html#getCallerClass())
> 
> if it was called from outside DebugGraphics, and if so install some other graphics instead.
> 
> something like .. 
> if (graphics == null && stackWalker.getCallerClass() != this.class ) {
>    BufferedImage bi = new BufferedImage(1,1,BufferedImage.TYPE_INT_RGB);
>    graphics = bi.createGraphics();
> }

@prrace, I have updated the PR, let me know if its ok now......

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

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



More information about the client-libs-dev mailing list