JPAContainer.refreshItem NPE

Hello, I’m using JPAContainer together with FilterTable which has my own FieldFactory set. The createField method of this FieldFactory returns null values for some rows because I want to have them uneditable. When calling jpaContainer.refresh() there is NPE in JPAContainer.refreshItem(Object itemId) method.
To be able to use it I’ve modified the code of that method to following where I added check for null value:


    @Override
    @SuppressWarnings("unchecked")
    public void refreshItem(Object itemId) {
        LinkedList<WeakReference<JPAContainerItem<T>>> linkedList;
        synchronized (getItemRegistry()) {
            LinkedList<WeakReference<JPAContainerItem<T>>> linkedList2 = getItemRegistry().get(itemId);
            if (linkedList2 != null) {
                linkedList = (LinkedList<WeakReference<JPAContainerItem<T>>>) linkedList2.clone();
            } else {
                linkedList = new LinkedList<WeakReference<JPAContainerItem<T>>>();
            }
        }
        for (WeakReference<JPAContainerItem<T>> weakReference : linkedList) {
            JPAContainerItem<T> jpaContainerItem = weakReference.get();
            if (jpaContainerItem != null) {
                jpaContainerItem.refresh();
            }
        }
    }

Is it ok that getItemRegistry().get(itemId) returns null for some itemIds? Is there just something wrong with my code somewhere or there really needs to be such a check in JPAContainer?

Hi,

At a quick glance of the sources I think that a null check would probably be needed there, just as you have figured out. Could you please create a ticket for this at
dev.vaadin.com
?

Thanks,
/Jonatan