NullPointerException from ToolBarBoxLayout

User 57295192cc

10-04-2013 11:59:04

Hi,


I found the following issue (was present in 5.12 and it's still there in 5.12.2):


When using MSketchPane on a dialog, launched from an applet for the first time, a NullPointerException is thrown:


NullPointerException
chemaxon.marvin.uif.util.swing.ToolBarBoxLayout.checkRequests(ToolBarBoxLayout.java:218)
chemaxon.marvin.uif.util.swing.ToolBarBoxLayout.preferredLayoutSize(ToolBarBoxLayout.java:187)
chemaxon.marvin.uif.util.swing.ToolBarLayout.preferredLayoutSize(ToolBarLayout.java:63)
chemaxon.marvin.uif.util.swing.SeparatorHandlerLayout$AbstractWrapper.preferredLayoutSize(SeparatorHandlerLayout.java:95)
java.awt.Container.preferredSize(Container.java:1597)
java.awt.Container.getPreferredSize(Container.java:1582)
javax.swing.JComponent.getPreferredSize(JComponent.java:1644)
cb.aloe.swing.tools.Dock.getPreferredToolBarDepth(Unknown Source)
cb.aloe.swing.tools.k.c(Unknown Source)
cb.aloe.swing.tools.a.getPreferredDepth(Unknown Source)
cb.aloe.swing.tools.i.preferredLayoutSize(Unknown Source)
java.awt.Container.preferredSize(Container.java:1597)
java.awt.Container.getPreferredSize(Container.java:1582)
javax.swing.JComponent.getPreferredSize(JComponent.java:1644)
java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:702)
java.awt.Container.preferredSize(Container.java:1597)
java.awt.Container.getPreferredSize(Container.java:1582)
javax.swing.JComponent.getPreferredSize(JComponent.java:1644)
java.awt.GridBagLayout.GetLayoutInfo(GridBagLayout.java:1092)
java.awt.GridBagLayout.getLayoutInfo(GridBagLayout.java:893)
java.awt.GridBagLayout.ArrangeGrid(GridBagLayout.java:2048)
java.awt.GridBagLayout.arrangeGrid(GridBagLayout.java:2008)
java.awt.GridBagLayout.layoutContainer(GridBagLayout.java:789)
java.awt.Container.layout(Container.java:1419)
java.awt.Container.doLayout(Container.java:1408)
java.awt.Container.validateTree(Container.java:1505)
java.awt.Container.validateTree(Container.java:1511)
java.awt.Container.validateTree(Container.java:1511)
java.awt.Container.validateTree(Container.java:1511)
java.awt.Container.validateTree(Container.java:1511)
java.awt.Container.validateTree(Container.java:1511)
java.awt.Container.validateTree(Container.java:1511)
java.awt.Container.validate(Container.java:1478)
java.awt.Window.pack(Window.java:716)


It only happens when I try to open the dialog for the first time, with an empty plugin cache. (Even after restarting the browser, but leaving the already loaded jars in the cache, it works fine.)


The dialog (with MSketchPane) is constructed in a separate thread -- I'm not sure whether this is important though.


Can you please look into this?


 


Many thanks,


Pál

ChemAxon 2c555f5717

10-04-2013 14:13:01

I have made a workaround.


The problem can be that one of your top level container (or the used layout manager) misses the minimum size, maximum size or preferred size attributes. Now I can not think of anything else.


If you are using an applet, why don't you use our applet? We have JMSketch and JMView as applet classes. We also advise you to use our applet script: marvin.js, to show one of our applets. It is easier to embed that supported solution to a HTML conatiner than building a new custom applications. (I might misunderstood you.)


 


Regards:
 Balázs

User 57295192cc

10-04-2013 14:29:28

Hi Balázs,


Thanks for the quick reply! We use MSketchPane embedded into a dialog, which is launched from our own applet (so using your applets is not an option as MSketchPane is embedded in our own application).


I'll try to play around with setting the size attributes (we use a BorderLayout and the dialog is really simple). Any idea as to why it only happens once and only when launched with an empty plugin cache?


My current workaround is to simply catch the NPE and try again. I'll also double check if calling the constructor on the EDT changes anything.


Thanks,


Pál

User 57295192cc

10-04-2013 14:42:56

I did some more testing:


Setting sizes explicitly either for the panel containing MSketchPane or for the dialog itself didn't fix it.


But I can confirm it only happens when the dialog (along with MSketchPane) is constructed on a separate thread (needed to provide some visual feedback if it takes long when new jars need to be loaded etc.)

ChemAxon 2c555f5717

10-04-2013 14:52:36

The code that throws the NullPointerException is responsible to guess the sufficient size of a toolbar. For this it needs the size of the toolbar components (like buttons, icons, etc). It is posisble that some resorces are not available yet to determine their size (But the request of any other has started tahir download.) or they are about to be painted and their size are under calculation.  You can try to synchronise about this, EDT can be a solution but I am not sure. We will try to reproduce your case, and find out a solution or a workaround.

User 57295192cc

10-04-2013 15:25:56

Even though the behaviour I've seen is somewhat unexpected, I think it's mainly my fault: calling Window.pack() _not_ from the EDT is probably wrong...


Thanks very much again for your help,


Pál