-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move up null check in GEF viewer when the selected editpart is updated.
The selection inside a GEF viewer is assumed to always be non-null. But because the (implicit) null check is done after the editpart is added to the internal list, it leaves the viewer in an inconsistent state. To avoid this, the null check is done earlier, so that the exception is thrown before the internal model is modified. Resolves #433
- Loading branch information
Showing
3 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
org.eclipse.gef.tests/src/org/eclipse/gef/test/GraphicalViewerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Patrick Ziegler and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Patrick Ziegler - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.gef.test; | ||
|
||
import static org.junit.Assert.assertThrows; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.eclipse.jface.viewers.IStructuredSelection; | ||
import org.eclipse.jface.viewers.StructuredSelection; | ||
|
||
import org.eclipse.gef.GraphicalViewer; | ||
import org.eclipse.gef.ui.parts.GraphicalViewerImpl; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class GraphicalViewerTest { | ||
private GraphicalViewer viewer; | ||
|
||
@Before | ||
public void setUp() { | ||
viewer = new GraphicalViewerImpl(); | ||
} | ||
|
||
/** | ||
* Appending a {@code null} edit part shouldn't leave the viewer in an | ||
* inconsistent state. | ||
*/ | ||
@Test | ||
public void testAppendNullSelection() { | ||
assertThrows(NullPointerException.class, () -> viewer.appendSelection(null)); | ||
assertTrue(viewer.getSelectedEditParts().isEmpty()); | ||
} | ||
|
||
/** | ||
* Setting a {@code null} edit part shouldn't leave the viewer in an | ||
* inconsistent state. | ||
*/ | ||
@Test | ||
public void testSetNullSelection() { | ||
IStructuredSelection selection = new StructuredSelection(new Object[] { null }); | ||
assertThrows(NullPointerException.class, () -> viewer.setSelection(selection)); | ||
assertTrue(viewer.getSelectedEditParts().isEmpty()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters