Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

NullPointerException in StateHolderSaver contructor #4092

Closed
javaserverfaces opened this issue Dec 26, 2015 · 15 comments
Closed

NullPointerException in StateHolderSaver contructor #4092

javaserverfaces opened this issue Dec 26, 2015 · 15 comments

Comments

@javaserverfaces
Copy link
Collaborator

Seems like the contructor for StateHolderSaver is not null safe?
I got a NullPointerException in a table when the state should be saved.

  1. Location in code where the constructors i called - UIComponentBase, method saveAttachedState, row 1175```
    ...
    resultList.add(new StateHolderSaver(context, value));
    ...
    
    
  2. In my case the 'value' above is null so that StateHolderSaver constructor will then throw a NullPointerException since the code invokes toSave.getClass().getName(). Se below:```
    ....
    public StateHolderSaver(FacesContext context, Object toSave) {
    this.className = toSave.getClass().getName();
    ....
    }
    
    
  • This must be a very common use case (that a 'value' is null to be persisted/restored). Is it my code that´s using the StateHolderSaver in a special way or is this a new bug in 2.1.12?

Environment

Mojarra 2.2.12, Primefaces 5.3

Affected Versions

[2.2.12]

@javaserverfaces
Copy link
Collaborator Author

Reported by acerhigh2015

@javaserverfaces
Copy link
Collaborator Author

Was assigned to ZhangXinyuan

@javaserverfaces
Copy link
Collaborator Author

acerhigh2015 said:
After further investigation I notice that this exception will be thrown for ANY component that will store a state i.e attachedObject that is a Map if that Map has any key that is mapped to a value that is null.

} else if(newWillSucceed && attachedObject instanceof Map) {
Map attachedMap1 = (Map)attachedObject;
resultList = null;
Iterator i$ = attachedMap1.entrySet().iterator();

while(true) {
    Object key;
    do {
        Entry entry;
        do {
            if(!i$.hasNext()) {
result = resultList;
return result;
            }

            entry = (Entry)i$.next();
            key = entry.getKey();
        } while(key instanceof StateHolder && ((StateHolder)key).isTransient());

        value = entry.getValue();
    } while(value instanceof StateHolder && ((StateHolder)value).isTransient());

    if(resultList == null) {
        resultList = new ArrayList(attachedMap1.size() * 2 + 1);
        resultList.add(new StateHolderSaver(context, mapOrCollectionClass));
    }

    resultList.add(new StateHolderSaver(context, key));
    resultList.add(new StateHolderSaver(context, value));             <<<--- this will throw NullPointerException
}

Other types of attachedObject, Collections etc, seems to have sufficient null check and therefor will not showcase this bug.

@javaserverfaces
Copy link
Collaborator Author

acerhigh2015 said:
Have someone looked into this, would be good to have some sort of notification of the status of the story/issue?

@javaserverfaces
Copy link
Collaborator Author

ren.zhijun.oracle said:
Hi I am taking care of these JIRA issues including this one, will update you once done.

@javaserverfaces
Copy link
Collaborator Author

acerhigh2015 said:
Ok, thanks for the update in the story. Just contact me if there are some questions or something I can help with.

@javaserverfaces
Copy link
Collaborator Author

acerhigh2015 said:
Hi again,
can someone please fix this bug. This is obviously a bug that has to be fixed ASAP.

@javaserverfaces
Copy link
Collaborator Author

acerhigh2015 said:
Hi, can you comment back the plan about when this issue can be fixed?
(It has been 4 month now, on this severe bug, and no feedback yet)

@javaserverfaces
Copy link
Collaborator Author

ren.zhijun.oracle said:
Hi, Emma is working on this now, will get fixed soon, please stay tuned.

@javaserverfaces
Copy link
Collaborator Author

acerhigh2015 said:
Ok, thanks for the quick reply, I wait for Emmas fix then.

@javaserverfaces
Copy link
Collaborator Author

zhangxinyuan said:
hi,
I want to reproduce this bug, could you offer me the test case?

@javaserverfaces
Copy link
Collaborator Author

ren.zhijun.oracle said:
Hi, Can you provide a test war application for this bug?

@javaserverfaces
Copy link
Collaborator Author

acerhigh2015 said:
Hi, sorry for taking some time before responding!

Sorry, have no time to do that at the moment. If that it needed I will try o fix that next month. Else, it is an "obvious bug" and should be able to covered it with a "simple" junit test.
See my comment I made "26/Dec/15 10:19 PM", there you can see that in case for storing Map with a "value" that is null the code will throw a NullpointerException.

Is it still needed with a test-war?

@javaserverfaces
Copy link
Collaborator Author

This issue was imported from java.net JIRA JAVASERVERFACES-4088

@xinyuan-zhang
Copy link
Contributor

pushed to 2.2.x

jsf-tools/template-src/StateHolderSaver.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

arjantijms pushed a commit that referenced this issue Sep 9, 2017
https://github.com/javaserverfaces/mojarra/issues/4092

Conflicts:
	jsf-tools/template-src/StateHolderSaver.java

modified:   jsf-tools/template-src/StateHolderSaver.java
@arjantijms arjantijms added this to the 2.3.3 milestone Oct 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants