[ZEST] NPEs due to invalid GraphViewer selections [message #720459] |
Tue, 30 August 2011 16:00 |
Eclipse User |
|
|
|
Originally posted by:
We are using the GraphViewer from GEF 3.6.1 in an Eclipse View (zest
core plugin has version 1.2.0) and observe that we get always
NullPointerExceptions since we have added a context menu to this viewer.
It turned out that the cause of these is that the GraphViewer produces
ISelection values which are not empty (the sequence of elements has a
size > 0), but the elements have null values. But null values are not
acceptable contents for any IStructuredSelection as described in the
corresponding constructors of StructuredSelection. It turned out that
these selection values are produced by quering the data property of the
GraphNode contents of the viewer. But looking at the GraphNode
description there is nothing mentioned that the data property must have
a well-defined value. In contrast, several constructors exist, that
implicitly set the data value to null.
IMO there are two choices to fix this:
1) The GraphViewer should document the relation between selection and
data, in this case it seems that user code can never legally construct
GraphNode objects with null data.
2) The GraphViewer takes care when constructing the selection values
within AbstractStructuredGraphViewer#getSelectionFromWidget() to not add
null data values to the complete selection.
There is a worse problem with GraphConnection: In this case there exists
only a single constructor which does implicitly set the data property of
the GraphItem to null. In this case I would strongly recommend to
provide a further constructors that allows setting the data as well.
As a workaround for this problem we currently have changed our code and
always set a unique data value per GraphNode and per GraphConnection.
Thanks & Greetings from Bremen
Daniel Krügler
|
|
|
Re: [ZEST] NPEs due to invalid GraphViewer selections [message #720732 is a reply to message #720459] |
Wed, 31 August 2011 07:00 |
Eclipse User |
|
|
|
Originally posted by:
On 2011-08-30 18:00, Daniel Krügler wrote:
> We are using the GraphViewer from GEF 3.6.1 in an Eclipse View (zest
> core plugin has version 1.2.0) and observe that we get always
> NullPointerExceptions since we have added a context menu to this viewer.
> It turned out that the cause of these is that the GraphViewer produces
> ISelection values which are not empty (the sequence of elements has a
> size > 0), but the elements have null values. But null values are not
> acceptable contents for any IStructuredSelection as described in the
> corresponding constructors of StructuredSelection.
Let me emphasize that the NPEs don't appear in our code and we cannot
fix the problem by checking the contents of the ISelection objects
produced by the viewer ourselves. The NPEs do occur deep within the
Eclipse object-contribution handler code that is invoked during the
handling of the menu contributions of the aforementioned context menu.
Therefore this is a contract violation by the GraphViewer which causes
the problem.
- Daniel Krügler
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02917 seconds