gwtproject / gwt

GWT Open Source Project
http://www.gwtproject.org
1.52k stars 374 forks source link

NPE in TreeViewModel when the underlying DataProvider is null #7480

Closed dankurka closed 9 years ago

dankurka commented 9 years ago

Originally reported on Google Code with ID 7483

Found in GWT Release (e.g. 2.4.0, 2.5.0 RC): 2.4.0
Encountered on OS / Browser (e.g. WinXP, IE8-9, FF7): MacOS X, Chrome

Detailed description (please be as specific as possible):

An NPE is thrown in the app when trying to initialize a CellTree with a TreeViewModel
that has a null DataProvider instance for the 'base' (when tree is empty or null) case
for getNodeInfo(T value) method. This should be handled gracefully since it is always
possible to initialize the DataProvider later in the application lifecycle.

Stacktrace:

java.lang.NullPointerException: null
    at com.google.gwt.view.client.TreeViewModel$DefaultNodeInfo.setDataDisplay(TreeViewModel.java:112)
    at com.google.gwt.user.cellview.client.CellTreeNodeView.onOpen(CellTreeNodeView.java:1087)
    at com.google.gwt.user.cellview.client.CellTreeNodeView.setOpen(CellTreeNodeView.java:903)
    at com.google.gwt.user.cellview.client.CellTree.<init>(CellTree.java:603)
    at com.google.gwt.user.cellview.client.CellTree.<init>(CellTree.java:553)

Shortest code snippet which demonstrates issue (please indicate where
actual result differs from expected result):

See description.

class X implements TreeViewModel {

@Override
    public <T> NodeInfo<?> getNodeInfo(T value) {

        if (value == null) 
            return new DefaultNodeInfo<Y>(null, new TextCell());
                }

}

class Z implements EntryPoint {
public void onModuleLoad() {
final CellTree cellTree = new CellTree(new X(), null);
}
}

Workaround if you have one:

precondition to getNodeInfo() : DataProvider shouldn't be null

Links to relevant GWT Developer Forum posts:

Link to patch posted at http://gwt-code-reviews.appspot.com:

Reported by obvyst on 2012-07-04 09:57:20

dankurka commented 9 years ago

Reported by dankurka@google.com on 2013-05-27 18:17:39