PDA

View Full Version : NPE & weak references when using toolbars



Catalin Sanda
Dec 8th, 2004, 08:43 AM
Hello,

I have a problem with the toolbar buttons. I bind a command to a toolbar button and a menu entry, depending on certain events I enable or disable the command, enabling or disabling the corresponding components, but after a while I get a NullPointerException because the command manager uses weak references and the GC deallocates the buttons.

What am I doing wrong?

Tks
Catalin

snpe
Dec 8th, 2004, 10:49 AM
Do You use TargetableActionCommand
If yes, then you have problem with ApplicationPage@fireFocusGained/FireFocusLost
It realocate TargetableActionCommand - try synchronize with this methods or extend DefaultApplicationPage and exclude this methods

regards

Keith Donald
Dec 8th, 2004, 12:56 PM
Hmm... interesting. And these buttons are referenced by the containers containing them? If that's the case, I don't see how they could be garbage collected. We certainly need a JIRA issue for this if this indeed is happening consistently.

Keith

oliverhutchison
Dec 8th, 2004, 03:49 PM
This is caused by some very whacky code in CommandFaceButtonManager ;-) I'm sitting on a patch but have not committed.

Though this NPE can only happen if the button GCd so I suspect something is throwing away and recreating the toolbar or menu in this case. I hit it when I was throwing away popup menus.

I'll commit the patch now.

Ollie

Catalin Sanda
Dec 9th, 2004, 04:14 AM
I tested the patch, and it works.
tks a lot!

Catalin