Issue Details (XML | Word | Printable)

Key: JAVASERVERFACES-1716
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Unassigned
Reporter: hanafey
Votes: 3
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
javaserverfaces

StateSaverHolder and Objects not implementing StateHolder nor Serializable State

Created: 25/Jun/10 04:52 AM   Updated: 04/Dec/12 03:13 PM   Resolved: 04/Dec/12 03:13 PM
Component/s: state saving
Affects Version/s: 2.0.2
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive JAVASERVERFACES-1716-testcase.zip (4.79 MB) 09/Nov/11 04:18 PM - Adrian Gygax

Environment:

Operating System: All
Platform: All


Issuezilla Id: 1,716
Status Whiteboard:

size_medium importance_medium

Tags:
Participants: Adrian Gygax, hanafey, Manfred Riem and rogerk



rogerk added a comment - 28/Jun/10 10:00 AM

triage


hanafey added a comment - 22/Jul/10 10:09 AM

Any further comments??


rogerk added a comment - 18/Nov/10 05:26 PM

triage


Adrian Gygax added a comment - 09/Nov/11 04:18 PM - edited

Attached a small Eclipse project containing a testcase demostrating the problem and a patched StateHolderSaver which fixes the bug.

The problem is in the constructor of StateHolderSaver which doesn't handle the case of a not serializable class correctly. StateHolderSaver.restore specifies, that for a class which is not serializable "className" and "savedState" are both expected to be null. However the constructor also sets the className if a class is not serializable:

public StateHolderSaver(FacesContext context, Object toSave) {

        className = toSave.getClass().getName();
        
        if (toSave instanceof StateHolder) {
            //...
        } else if (toSave instanceof Serializable) {
            savedState = (Serializable) toSave;
            className = null;
        }
    }

My recommended fix is to move the className initialization into the "if instance of StateHolder" block, because this is the only case where "className" is expected to have a non-null value:

public StateHolderSaver(FacesContext context, Object toSave) {
        
        if (toSave instanceof StateHolder) {
            className = toSave.getClass().getName();
            //...
        } else if (toSave instanceof Serializable) {
            savedState = (Serializable) toSave;
        }
    }

Manfred Riem added a comment - 04/Dec/12 03:13 PM

Looking at the code for StateHolderSaver on trunk shows me that the className is used by the restore method. Even in the case the submitter asserts it is not. So I am closing this as "Won't fix" since the restore method requires the className to be available during restore.