Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 494705

Summary: FXTypeTool doesn't check if active view is null
Product: [Tools] GEF Reporter: Colin Sharples <ctg>
Component: GEF MVCAssignee: gef-inbox <gef-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: matthias.wienand
Version: 0.2.0   
Target Milestone: 4.0.0 (Neon) RC3   
Hardware: PC   
OS: Windows NT   
Whiteboard:

Description Colin Sharples CLA 2016-05-26 22:16:55 EDT
In the FXTypeTool pressedFilter event handle, it does not check if the activeViewer is null when the event target is a JavaFX Node. This can legitimately happen if the FXViewer is embedded in a non-GEF managed JavaFX container, e.g. when running GEF4 in a JavaFX-rendered e4 application.

This results in an IllegalArgumentException being thrown from AbstractTool.setActivePolicies().

The code in question is lines 136-161:

if (target instanceof Node) {
    targetNode = (Node) target;
    activeViewer = FXPartUtils.retrieveViewer(getDomain(), targetNode);
} else if (target instanceof Scene) {
    // first focused viewer in that scene
    for (IViewer<Node> v : getDomain().getViewers().values()) {
        if (v.getRootPart().getVisual().getScene() == target) {
            if (v.isViewerFocused()) {
                activeViewer = v;
		break;
            }
        }
    }
    if (activeViewer == null) {
        // No focused viewer could be found for the
        // target Scene.
        return;
    }
    targetNode = activeViewer.getRootPart().getVisual();
} else {
    throw new IllegalStateException("Unsupported event target: " + target);
}

The check for activeViewer being null is only in the second branch of the if statement - this should be moved to outside of the if/else block
Comment 1 Matthias Wienand CLA 2016-05-27 03:26:51 EDT
I ensured that the target node is only evaluated in the else-if-branch if an active viewer could be found, and added the missing null-check after the if/else block. The code is published on the master branch, therefore, I resolve this ticket as fixed for 4.0.0 RC3.