eclipse-windowbuilder / windowbuilder

Eclipse Windowbuilder
https://projects.eclipse.org/projects/tools.windowbuilder
Eclipse Public License 1.0
78 stars 30 forks source link

AssertionFailedException when adding/removing element from JFrame #813

Closed ptziegler closed 2 months ago

ptziegler commented 2 months ago

The following method introduced with https://github.com/eclipse-windowbuilder/windowbuilder/pull/182 creates a partially initialized instance of the ImplicitLayoutCreationSupport:

https://github.com/eclipse-windowbuilder/windowbuilder/blob/a28301b17ac3cfef7c4a3d3adb2533bccae6f123/org.eclipse.wb.swing/src/org/eclipse/wb/internal/swing/model/component/ContainerInfo.java#L626-L650

When a new instance of this CreationSupport is created, one must also call setJavaInfo. The result of this oversight can be observed with the following example:

public class MyFrame extends JFrame {

    private static final long serialVersionUID = 1L;
    private JPanel contentPane;

    /**
     * Create the frame.
     */
    public MyFrame() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

        setContentPane(contentPane);
        contentPane.setLayout(null);
    }
}

When adding and immediately removing a JPanel, the editor crashes with the following exception:


org.eclipse.wb.internal.core.utils.check.AssertionFailedException: null argument
    at org.eclipse.wb.internal.core.utils.check.Assert.fail(Assert.java:225)
    at org.eclipse.wb.internal.core.utils.check.Assert.isNotNull(Assert.java:174)
    at org.eclipse.wb.internal.core.utils.check.Assert.isNotNull(Assert.java:159)
    at org.eclipse.wb.core.model.ObjectInfo.addChild(ObjectInfo.java:181)
    at org.eclipse.wb.core.model.ObjectInfo.addChild(ObjectInfo.java:164)
    at org.eclipse.wb.internal.swing.model.layout.ImplicitLayoutCreationSupport$2.childRemoveAfter(ImplicitLayoutCreationSupport.java:59)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.eclipse.wb.core.model.broadcast.BroadcastSupport.lambda$0(BroadcastSupport.java:207)
    at org.eclipse.wb.core.model.broadcast.ObjectEventListener$ByteBuddy$uhzXxpnH.childRemoveAfter(Unknown Source)
    at org.eclipse.wb.core.model.ObjectInfo.removeChild(ObjectInfo.java:248)
    at org.eclipse.wb.internal.swing.model.layout.absolute.AbsoluteLayoutCreationSupport.delete(AbsoluteLayoutCreationSupport.java:83)
    at org.eclipse.wb.core.model.JavaInfo$7.run(JavaInfo.java:818)
    at org.eclipse.wb.internal.core.utils.execution.ExecutionUtils.run(ExecutionUtils.java:331)
    at org.eclipse.wb.core.model.JavaInfo.delete(JavaInfo.java:805)
    at org.eclipse.wb.internal.core.model.JavaInfoUtils.deleteJavaInfo(JavaInfoUtils.java:2048)
    at org.eclipse.wb.internal.core.model.creation.ConstructorCreationSupport.delete(ConstructorCreationSupport.java:418)
    at org.eclipse.wb.core.model.JavaInfo$7.run(JavaInfo.java:818)
    at org.eclipse.wb.internal.core.utils.execution.ExecutionUtils.run(ExecutionUtils.java:331)
    at org.eclipse.wb.core.model.JavaInfo.delete(JavaInfo.java:805)
    at org.eclipse.wb.core.model.AbstractComponentInfo.delete(AbstractComponentInfo.java:226)
    at org.eclipse.wb.internal.core.editor.actions.DeleteAction$2.executeEdit(DeleteAction.java:123)
    at org.eclipse.wb.core.gef.command.EditCommand.lambda$0(EditCommand.java:50)
    at org.eclipse.wb.internal.core.utils.execution.ExecutionUtils.run(ExecutionUtils.java:331)
    at org.eclipse.wb.core.gef.command.EditCommand.execute(EditCommand.java:50)
...