Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 258016 - [PropertiesView] NPE in org.eclipse.ui.views.properties.PropertySheetViewer
Summary: [PropertiesView] NPE in org.eclipse.ui.views.properties.PropertySheetViewer
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.5   Edit
Assignee: Eric Moffatt CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-09 00:56 EST by Ian Phillips CLA
Modified: 2009-03-10 13:04 EDT (History)
1 user (show)

See Also:


Attachments
Patch that safes up the code (1.32 KB, patch)
2008-12-22 10:29 EST, Eric Moffatt CLA
no flags Details | Diff
Patch that removes copy/paste artefacts as well as improving code safety. (1.69 KB, patch)
2009-02-10 07:45 EST, Ian Phillips CLA
emoffatt: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Phillips CLA 2008-12-09 00:56:09 EST
At line 720. If the selection is null this will result in an NPE. Here is the offending code snippet:

714:  // get the new selection
715:  TreeItem[] sel = new TreeItem[] { selection };
716:  if (sel.length == 0) {
717:      setMessage(null);
718:      setErrorMessage(null);
719:   } else {
720:      Object object = sel[0].getData(); // assume single selection

It would be better replaced with the following (sorry, no patch, I'm not set up for editing the platform!):

        // get the new selection
        TreeItem sel = new TreeItem[] { selection;
        if (selection == null) {
            setMessage(null);
            setErrorMessage(null);
        } else {
            Object object = selection.getData(); // assume single selection
            if (object instanceof IPropertySheetEntry) {
                // get the entry for this item
                IPropertySheetEntry activeEntry = (IPropertySheetEntry) object;

                // display the description for the item
                setMessage(activeEntry.getDescription());

                // activate a cell editor on the selection
                activateCellEditor(selection);
            }
        }

In fact, I'm not at all sure why the selection was being wrapped in a single element array at all, I'm guessing a holdover from old code?
Comment 1 Remy Suen CLA 2008-12-09 02:25:54 EST
Hi Ian, how did you get the NPE? What actions were you performing?
Comment 2 Ian Phillips CLA 2008-12-17 10:36:38 EST
This was sent back to the bugzilla daemon by mistake! So, err, sorry for the delay...

I was using an Eclipse RCP based product called Monkey World 3D (mw3d.org). In that I carried out the following steps:

1. select an object in the editor (this loads values into the property
  sheet, mostly represented by custom IPropertySource classes);

2. select a property to edit (in this case it is a custom CellEditor
  used to edit quaternion values);

3. hit enter.

It doesn't seem to matter if I make any changes to the editor or not. I would expect this to apply the editor changes and then leave the property cell in the selected state.

I will try some different combinations of steps to see if I can reproduce this any
other way, but the code snippet I highlighted does seem clearly incorrect, the as sel.length will ALWAYS be 1 so that test will always be false;
Comment 3 Eric Moffatt CLA 2008-12-22 10:26:40 EST
Ian, I could safe up the code but I suspect that this won't actually solve your issue. According to your steps there should have been a non-null value in 'e.item' when the 'widgetDefaultSelected' fired (since you had selected an entry in the tree).

I'm pretty sure (but not positive) that the various OS's will not send this event when there's no selected tree item. The only other way I can find into this code already checks to ensure that null is not passed. If true then you shouldn't ever be able to get this code to throw an NPE...

Can you attach a stack trace of the NPE (just to make sure that there isn't a third way in...;-).
Comment 4 Eric Moffatt CLA 2008-12-22 10:29:47 EST
Created attachment 121075 [details]
Patch that safes up the code


This will safe up the code but I'm yet to be convinced that it'll help the issue.

Ian, if you can please try this patch out but as previously stated I'm not sure that it'll actually fix the issue (but would make a good negative test).
Comment 5 Ian Phillips CLA 2009-02-10 07:45:07 EST
Created attachment 125234 [details]
Patch that removes copy/paste artefacts as well as improving code safety.

Hi Eric,

Sorry for taking so long to get back to you on this one.

That looks OK to me. I've tried it out and it seems to work although I think you are right in that it is possibly hiding another issue (very possibly in my code though, not Eclipse) rather than solving the root problem.

I'm also going to attach a different patch that I'd like to propose in place of yours. It's functionally the same but cleans up some of the copy-and-paste artefacts (as mentioned in my initial issue report).

Cheers,
Ian.
Comment 6 Eric Moffatt CLA 2009-02-10 13:48:37 EST
Thanks for the patch Ian! Nice one, removing the arcanity of turning a single element into an array...

Committed in >20090210. Applied Ian's patch.
Comment 7 Eric Moffatt CLA 2009-03-10 13:04:31 EDT
Verified (visually) in I20090310-0100.