You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Ian Robinson (JIRA)" <ji...@apache.org> on 2008/08/06 18:00:24 UTC

[jira] Created: (WW-2751) SessionMap containsKey will not find an object put into the map

SessionMap containsKey will not find an object put into the map
---------------------------------------------------------------

                 Key: WW-2751
                 URL: https://issues.apache.org/struts/browse/WW-2751
             Project: Struts 2
          Issue Type: Bug
          Components: Core Actions, Core Interceptors
    Affects Versions: 2.1.2, 2.1.1
            Reporter: Ian Robinson
            Priority: Minor


The put, get and remove methods on SessionMap do a toString() on the key they are dealing with.
containsKey is not overridden and so uses the method inherited from AbstractMap.

AbstractMap.containsKey(Object value) compares the object with the key entries using value.equals(e.getValue())

Therfore, if you put an object into the map, for instance an enum, containsKey(enum) wont find it.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-2751) SessionMap containsKey will not find an object put into the map

Posted by "James Holmes (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-2751?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

James Holmes updated WW-2751:
-----------------------------

            Flags: [Patch]
    Fix Version/s: 2.1.3

> SessionMap containsKey will not find an object put into the map
> ---------------------------------------------------------------
>
>                 Key: WW-2751
>                 URL: https://issues.apache.org/struts/browse/WW-2751
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions, Core Interceptors
>    Affects Versions: 2.1.1, 2.1.2
>            Reporter: Ian Robinson
>            Priority: Minor
>             Fix For: 2.1.3
>
>         Attachments: SessionMap.patch, SessionMapTest.patch
>
>
> The put, get and remove methods on SessionMap do a toString() on the key they are dealing with.
> containsKey is not overridden and so uses the method inherited from AbstractMap.
> AbstractMap.containsKey(Object value) compares the object with the key entries using value.equals(e.getValue())
> Therfore, if you put an object into the map, for instance an enum, containsKey(enum) wont find it.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (WW-2751) SessionMap containsKey will not find an object put into the map

Posted by "Nils-Helge Garli (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-2751?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nils-Helge Garli reassigned WW-2751:
------------------------------------

    Assignee: Nils-Helge Garli

> SessionMap containsKey will not find an object put into the map
> ---------------------------------------------------------------
>
>                 Key: WW-2751
>                 URL: https://issues.apache.org/struts/browse/WW-2751
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions, Core Interceptors
>    Affects Versions: 2.1.1, 2.1.2
>            Reporter: Ian Robinson
>            Assignee: Nils-Helge Garli
>            Priority: Minor
>             Fix For: 2.1.3
>
>         Attachments: SessionMap.patch, SessionMapTest.patch
>
>
> The put, get and remove methods on SessionMap do a toString() on the key they are dealing with.
> containsKey is not overridden and so uses the method inherited from AbstractMap.
> AbstractMap.containsKey(Object value) compares the object with the key entries using value.equals(e.getValue())
> Therfore, if you put an object into the map, for instance an enum, containsKey(enum) wont find it.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2751) SessionMap containsKey will not find an object put into the map

Posted by "Ian Robinson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2751?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44538#action_44538 ] 

Ian Robinson commented on WW-2751:
----------------------------------

The following three unit tests I feel demonstrate the issue... 

Firstly, these two show that mock is called with the string value of the key. Which works elsewhere since the key "KEY" is used...

    public void testGetObjectOnSessionMapUsesWrappedSessionsGetAttributeWithStringValue() throws Exception {
        Object key = new Object();
        Object value = new Object();
        sessionMock.expectAndReturn("getAttribute", new Constraint[]{
                new IsEqual(key.toString())
        }, value);

        SessionMap sessionMap = new SessionMap((HttpServletRequest) requestMock.proxy());
        assertEquals("Expected the get using KEY to return the value object setup in the mockSession", value, sessionMap.get(key));
        sessionMock.verify();
    }

    public void testPutObjectOnSessionMapUsesWrappedSessionsSetsAttributeWithStringValue() throws Exception {
        Object key = new Object();
        Object value = new Object();
        sessionMock.expect("getAttribute", new Constraint[]{new IsAnything()});
        sessionMock.expect("setAttribute", new Constraint[]{
                new IsEqual(key.toString()), new IsEqual(value)
        });

        SessionMap sessionMap = new SessionMap((HttpServletRequest) requestMock.proxy());
        sessionMap.put(key, value);
        sessionMock.verify();
    }
    
The following test fails for find the key...

    public void testContainsKeyWillFindAnObjectPutOnSessionMap() throws Exception {
        Object key = new Object();
        Object value = new Object();
        List<String> attributeNames = new ArrayList<String>();
        attributeNames.add(key.toString());
        Enumeration attributeNamesEnum = Collections.enumeration(attributeNames);
        sessionMock.expect("getAttribute", new Constraint[]{new IsAnything()});
        sessionMock.expect("setAttribute", new Constraint[]{
                new IsEqual(key.toString()), new IsEqual(value)
        });
        sessionMock.expectAndReturn("getAttributeNames", attributeNamesEnum);
        sessionMock.expect("getAttribute", new Constraint[]{ new IsEqual(key.toString())});
    	
        SessionMap sessionMap = new SessionMap((HttpServletRequest) requestMock.proxy());
        sessionMap.put(key, value);
        
        assertTrue("Expected to find key object session map", sessionMap.containsKey(key));
        sessionMock.verify();
    }




> SessionMap containsKey will not find an object put into the map
> ---------------------------------------------------------------
>
>                 Key: WW-2751
>                 URL: https://issues.apache.org/struts/browse/WW-2751
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions, Core Interceptors
>    Affects Versions: 2.1.1, 2.1.2
>            Reporter: Ian Robinson
>            Priority: Minor
>
> The put, get and remove methods on SessionMap do a toString() on the key they are dealing with.
> containsKey is not overridden and so uses the method inherited from AbstractMap.
> AbstractMap.containsKey(Object value) compares the object with the key entries using value.equals(e.getValue())
> Therfore, if you put an object into the map, for instance an enum, containsKey(enum) wont find it.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-2751) SessionMap containsKey will not find an object put into the map

Posted by "Ian Robinson (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-2751?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ian Robinson updated WW-2751:
-----------------------------

    Attachment: SessionMapTest.patch
                SessionMap.patch

I've attached possible patches for the SessionMap class and associated unit tests in SessionMapTest

> SessionMap containsKey will not find an object put into the map
> ---------------------------------------------------------------
>
>                 Key: WW-2751
>                 URL: https://issues.apache.org/struts/browse/WW-2751
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions, Core Interceptors
>    Affects Versions: 2.1.1, 2.1.2
>            Reporter: Ian Robinson
>            Priority: Minor
>         Attachments: SessionMap.patch, SessionMapTest.patch
>
>
> The put, get and remove methods on SessionMap do a toString() on the key they are dealing with.
> containsKey is not overridden and so uses the method inherited from AbstractMap.
> AbstractMap.containsKey(Object value) compares the object with the key entries using value.equals(e.getValue())
> Therfore, if you put an object into the map, for instance an enum, containsKey(enum) wont find it.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2751) SessionMap containsKey will not find an object put into the map

Posted by "Nils-Helge Garli (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2751?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45209#action_45209 ] 

Nils-Helge Garli commented on WW-2751:
--------------------------------------

Shouldn't SessionMap be restricted to SessionMap<String, Object> anyway? At least as long as it's in Struts and not XWork.

> SessionMap containsKey will not find an object put into the map
> ---------------------------------------------------------------
>
>                 Key: WW-2751
>                 URL: https://issues.apache.org/struts/browse/WW-2751
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions, Core Interceptors
>    Affects Versions: 2.1.1, 2.1.2
>            Reporter: Ian Robinson
>            Priority: Minor
>             Fix For: 2.1.3
>
>         Attachments: SessionMap.patch, SessionMapTest.patch
>
>
> The put, get and remove methods on SessionMap do a toString() on the key they are dealing with.
> containsKey is not overridden and so uses the method inherited from AbstractMap.
> AbstractMap.containsKey(Object value) compares the object with the key entries using value.equals(e.getValue())
> Therfore, if you put an object into the map, for instance an enum, containsKey(enum) wont find it.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WW-2751) SessionMap containsKey will not find an object put into the map

Posted by "Nils-Helge Garli (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-2751?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nils-Helge Garli resolved WW-2751.
----------------------------------

    Resolution: Fixed

> SessionMap containsKey will not find an object put into the map
> ---------------------------------------------------------------
>
>                 Key: WW-2751
>                 URL: https://issues.apache.org/struts/browse/WW-2751
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions, Core Interceptors
>    Affects Versions: 2.1.1, 2.1.2
>            Reporter: Ian Robinson
>            Assignee: Nils-Helge Garli
>            Priority: Minor
>             Fix For: 2.1.3
>
>         Attachments: SessionMap.patch, SessionMapTest.patch
>
>
> The put, get and remove methods on SessionMap do a toString() on the key they are dealing with.
> containsKey is not overridden and so uses the method inherited from AbstractMap.
> AbstractMap.containsKey(Object value) compares the object with the key entries using value.equals(e.getValue())
> Therfore, if you put an object into the map, for instance an enum, containsKey(enum) wont find it.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.