enhancement
critical
major
minor
minor
Extracted from Ticket #26142.
If you drag text onto a TreeGrid with a TableDrop configuration, you get an NPE:
Caused by: java.lang.NullPointerException
at com.top_logic.layout.dnd.DnD.getDndData(DnD.java:53)
at com.top_logic.layout.table.control.TableControl$DnDTableDragOverAction.executeChecked(TableControl.java:2301)
at com.top_logic.layout.table.control.TableControl$CheckedTableCommand.execute(TableControl.java:1304)
at com.top_logic.layout.table.control.TableControl$TableCommand.execute(TableControl.java:1254)
at com.top_logic.layout.basic.AbstractControlBase.executeCommand(AbstractControlBase.java:888)
at com.top_logic.layout.basic.component.ControlSupport.executeCommand(ControlSupport.java:221)
at com.top_logic.layout.basic.component.ControlComponent$DispatchAction.handleCommand(ControlComponent.java:231)
at com.top_logic.tool.boundsec.CommandHandlerUtil.handleCommand(CommandHandlerUtil.java:27)
at com.top_logic.mig.html.layout.LayoutComponent.dispatchCommand(LayoutComponent.java:2805)
at com.top_logic.mig.html.layout.CommandDispatcher.internalDispatchCommand(CommandDispatcher.java:192)
The NullPointerException is a general issue caused by the switch to pre-validation introduced by Ticket #23472.
For security reasons, browsers only provide `event.dataTransfer` while handling a drop; otherwise, the value is `undefined`. Due to the changes in #23472, drag-and-drop data is now stored in the `window` object, specifically in `window.tlDnDData`. This data is populated during ` dragStart`. This means the data is also available during `dragOver `, in particular, and can be included in the calculation to determine whether a drop is possible at that point.
The NullPointerException now occurs if any text (e.g., the component name in the toolbar) that does not originate from a table or tree is dragged over a component that has a drop handler. Since the handler that populates ` window.tlDnDData ` is not executed during `dragStart `—because the event handler is registered only for tables and trees—the data is empty, and thus the DnD cannot be parsed during ` dragOver`. This ultimately results in a NullPointerException.
Implementation
- The exception can be prevented by adding a check for the existence of ` window.tlDnDData ` during ` dragOver `.
- The contents of `window.tlDnDData ` are reset at the end of a drag operation, ensuring that no inconsistent state occurs after a valid drag-and-drop followed by a drag-and-drop of text.
Test
Navigate to the Technical Demo > Components > Drag & Drop view and drag a text onto the factory floor plan. No exception should be thrown.