View | Details | Raw Unified | Return to bug 58284
Collapse All | Expand All

(-)java/org/apache/catalina/ha/session/DeltaSession.java (-6 / +12 lines)
Lines 24-29 Link Here
24
import java.io.ObjectOutput;
24
import java.io.ObjectOutput;
25
import java.io.ObjectOutputStream;
25
import java.io.ObjectOutputStream;
26
import java.io.Serializable;
26
import java.io.Serializable;
27
import java.io.WriteAbortedException;
27
import java.security.Principal;
28
import java.security.Principal;
28
import java.util.ArrayList;
29
import java.util.ArrayList;
29
import java.util.Hashtable;
30
import java.util.Hashtable;
Lines 771-779 Link Here
771
        isValid = true;
772
        isValid = true;
772
        for (int i = 0; i < n; i++) {
773
        for (int i = 0; i < n; i++) {
773
            String name = (String) stream.readObject();
774
            String name = (String) stream.readObject();
774
            Object value = stream.readObject();
775
            final Object value;
775
            if ( (value instanceof String) && (value.equals(NOT_SERIALIZED)))
776
            try {
776
                continue;
777
                value = stream.readObject();
778
            } catch (WriteAbortedException wae) {
779
                if (wae.getCause() instanceof NotSerializableException) {
780
                    // Skip non serializable attributes
781
                    continue;
782
                }
783
                throw wae;
784
            }
777
            attributes.put(name, value);
785
            attributes.put(name, value);
778
        }
786
        }
779
        isValid = isValidSave;
787
        isValid = isValidSave;
Lines 871-879 Link Here
871
            try {
879
            try {
872
                stream.writeObject(saveValues.get(i));
880
                stream.writeObject(saveValues.get(i));
873
            } catch (NotSerializableException e) {
881
            } catch (NotSerializableException e) {
874
                log.error(sm.getString("standardSession.notSerializable",saveNames.get(i), id), e);
882
                log.error(sm.getString("standardSession.notSerializable", saveNames.get(i), id), e);
875
                stream.writeObject(NOT_SERIALIZED);
876
                log.error("  storing attribute '" + saveNames.get(i)+ "' with value NOT_SERIALIZED");
877
            }
883
            }
878
        }
884
        }
879
885
(-)java/org/apache/catalina/session/StandardSession.java (-22 / +16 lines)
Lines 22-27 Link Here
22
import java.io.ObjectInputStream;
22
import java.io.ObjectInputStream;
23
import java.io.ObjectOutputStream;
23
import java.io.ObjectOutputStream;
24
import java.io.Serializable;
24
import java.io.Serializable;
25
import java.io.WriteAbortedException;
25
import java.security.AccessController;
26
import java.security.AccessController;
26
import java.security.Principal;
27
import java.security.Principal;
27
import java.security.PrivilegedAction;
28
import java.security.PrivilegedAction;
Lines 113-118 Link Here
113
    // ----------------------------------------------------------- Constructors
114
    // ----------------------------------------------------------- Constructors
114
115
115
116
117
    
116
    /**
118
    /**
117
     * Construct a new Session associated with the specified Manager.
119
     * Construct a new Session associated with the specified Manager.
118
     *
120
     *
Lines 141-154 Link Here
141
143
142
144
143
    /**
145
    /**
144
     * The dummy attribute value serialized when a NotSerializableException is
145
     * encountered in <code>writeObject()</code>.
146
     */
147
    protected static final String NOT_SERIALIZED =
148
        "___NOT_SERIALIZABLE_EXCEPTION___";
149
150
151
    /**
152
     * The collection of user data attributes associated with this Session.
146
     * The collection of user data attributes associated with this Session.
153
     */
147
     */
154
    protected Map<String, Object> attributes = new ConcurrentHashMap<>();
148
    protected Map<String, Object> attributes = new ConcurrentHashMap<>();
Lines 1631-1639 Link Here
1631
        isValid = true;
1625
        isValid = true;
1632
        for (int i = 0; i < n; i++) {
1626
        for (int i = 0; i < n; i++) {
1633
            String name = (String) stream.readObject();
1627
            String name = (String) stream.readObject();
1634
            Object value = stream.readObject();
1628
            final Object value;
1635
            if ((value instanceof String) && (value.equals(NOT_SERIALIZED)))
1629
            try {
1636
                continue;
1630
                value = stream.readObject();
1631
            } catch (WriteAbortedException wae) {
1632
                if (wae.getCause() instanceof NotSerializableException) {
1633
                    // Skip non serializable attributes
1634
                    continue;
1635
                }
1636
                throw wae;
1637
            }
1637
            if (manager.getContext().getLogger().isDebugEnabled())
1638
            if (manager.getContext().getLogger().isDebugEnabled())
1638
                manager.getContext().getLogger().debug("  loading attribute '" + name +
1639
                manager.getContext().getLogger().debug("  loading attribute '" + name +
1639
                    "' with value '" + value + "'");
1640
                    "' with value '" + value + "'");
Lines 1709-1726 Link Here
1709
            try {
1710
            try {
1710
                stream.writeObject(saveValues.get(i));
1711
                stream.writeObject(saveValues.get(i));
1711
                if (manager.getContext().getLogger().isDebugEnabled())
1712
                if (manager.getContext().getLogger().isDebugEnabled())
1712
                    manager.getContext().getLogger().debug
1713
                    manager.getContext().getLogger().debug(
1713
                        ("  storing attribute '" + saveNames.get(i) +
1714
                            "  storing attribute '" + saveNames.get(i) + "' with value '" + saveValues.get(i) + "'");
1714
                        "' with value '" + saveValues.get(i) + "'");
1715
            } catch (NotSerializableException e) {
1715
            } catch (NotSerializableException e) {
1716
                manager.getContext().getLogger().warn
1716
                manager.getContext().getLogger()
1717
                    (sm.getString("standardSession.notSerializable",
1717
                        .warn(sm.getString("standardSession.notSerializable", saveNames.get(i), id), e);
1718
                     saveNames.get(i), id), e);
1719
                stream.writeObject(NOT_SERIALIZED);
1720
                if (manager.getContext().getLogger().isDebugEnabled())
1721
                    manager.getContext().getLogger().debug
1722
                       ("  storing attribute '" + saveNames.get(i) +
1723
                        "' with value NOT_SERIALIZED");
1724
            }
1718
            }
1725
        }
1719
        }
1726
1720
(-)test/org/apache/catalina/session/TestStandardSession.java (-8 / +16 lines)
Lines 26-34 Link Here
26
import java.util.Map;
26
import java.util.Map;
27
27
28
import org.junit.Assert;
28
import org.junit.Assert;
29
import org.junit.Ignore;
30
import org.junit.Test;
29
import org.junit.Test;
31
32
import org.apache.catalina.Manager;
30
import org.apache.catalina.Manager;
33
import org.apache.catalina.core.StandardContext;
31
import org.apache.catalina.core.StandardContext;
34
32
Lines 93-111 Link Here
93
    }
91
    }
94
92
95
93
94
    /**
95
     * See Bug 58284
96
     */
96
    @Test
97
    @Test
97
    @Ignore // This currently fails on de-serialization - bug 58284
98
    public void serializeSkipsNonSerializableAttributes() throws Exception {
98
    public void testSerializationComplex01() throws Exception {
99
        final String nonSerializableKey = "nonSerializable";
100
        final String nestedNonSerializableKey = "nestedNonSerializable";
101
        final String serializableKey = "serializable";
102
        final Object serializableValue = "foo";
99
103
100
        StandardSession s1 = new StandardSession(TEST_MANAGER);
104
        StandardSession s1 = new StandardSession(TEST_MANAGER);
101
        s1.setValid(true);
105
        s1.setValid(true);
102
        Map<String,NonSerializable> value = new HashMap<>();
106
        Map<String, NonSerializable> value = new HashMap<>();
103
        value.put("key", new NonSerializable());
107
        value.put("key", new NonSerializable());
104
        s1.setAttribute("attr01", value);
108
        s1.setAttribute(nestedNonSerializableKey, value);
109
        s1.setAttribute(serializableKey, serializableValue);
110
        s1.setAttribute(nonSerializableKey, new NonSerializable());
105
111
106
        StandardSession s2 = serializeThenDeserialize(s1);
112
        StandardSession s2 = serializeThenDeserialize(s1);
107
113
108
        validateSame(s1, s2, 0);
114
        Assert.assertNull(s2.getAttribute(nestedNonSerializableKey));
115
        Assert.assertNull(s2.getAttribute(nonSerializableKey));
116
        Assert.assertEquals(serializableValue, s2.getAttribute(serializableKey));
109
    }
117
    }
110
118
111
119
Lines 142-145 Link Here
142
150
143
    private static class NonSerializable {
151
    private static class NonSerializable {
144
    }
152
    }
145
}
153
}

Return to bug 58284