Container.remove issue
Alan Snyder
javalists at cbfiddle.com
Tue Nov 7 23:31:40 UTC 2023
> On Nov 7, 2023, at 2:57 PM, Philip Race <philip.race at oracle.com> wrote:
>
> I don't have a definite answer to your question, and for sure AWT docs may be a bit lacking,
> but there's also a lot of them so an answer may be buried somewhere.
>
> Not sure if you are saying you are in fact running "arbitrary code" in removeNotify() but
> I don't think that would be a good idea. You can observe in there but I'm not sure
> you should "do" anything. Also per the docs you need to call the superclass method as the first line.
>
> There's this old bug report https://bugs.openjdk.org/browse/JDK-4074274 which might be useful to read.
>
> -phil.
>
Interesting, but In this case, it is JTextComponent that is “doing something”.
public void removeNotify() {
super.removeNotify();
if (getFocusedComponent() == this) {
AppContext.getAppContext().remove(FOCUSED_COMPONENT);
}
}
Is there similar advice not to “do something” in a focus event listener?
I’m not seeing an argument against using some “defensive programming” in Container.remove.
It would be odd if some application depended upon removing a different component.
Alan
More information about the client-libs-dev
mailing list