<Swing Dev> RFR: 5015261: JInternalFrame causes NPE [v3]

Phil Race prr at openjdk.java.net
Sat Aug 14 18:54:23 UTC 2021


On Fri, 13 Aug 2021 04:34:52 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> JInternalFrame.getDesktopIcon() can be null as setDesktopIcon() can be called with null value. There are many places in JInternalFrame where getDesktopIcon() is accessed without null check which might cause NPE. 
>> Added null check for those cases.
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Spec clarification

JInternalFrame.JDesktopIcon seems to be a bit of a mess overall.

The class doc :
https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/JInternalFrame.JDesktopIcon.html
says :

This component represents an iconified version of a JInternalFrame. This API should NOT BE USED by Swing applications,
as it will go away in future versions of Swing as its functionality is moved into JInternalFrame. ...
If an application wants to display a desktop icon, it should create a JInternalFrame instance and iconify it.

I am not sure what that implies -iconification of a JInternalFrame isn't the same thing as setting it.

Are the setter and getter there only for the benefit of a L&F and really should not be public at all ?

The words "may" throw an NPE are not clear about when - I guess we aren't throwing an NPE right
at the moment you set it but aybe if you iconify the JInternalFrame it'll happen later ?
That's not great.

We should either prevent null being set or catch all those nulls.

And what if it is null some action needs to be taken - as Shannon wrote - "whatever that is"

On the basis that we need an icon else more problems occur I think we should just prevent it
and take the incompatibility of throwing NPE immediately  you try to set null.
Folks who are doing it are likely seeing random exceptions anyway at a later time !

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

PR: https://git.openjdk.java.net/jdk/pull/4989


More information about the swing-dev mailing list