Index: java/org/apache/catalina/ha/session/DeltaSession.java
===================================================================
--- java/org/apache/catalina/ha/session/DeltaSession.java (revision 1703678)
+++ java/org/apache/catalina/ha/session/DeltaSession.java (working copy)
@@ -24,6 +24,7 @@
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.io.WriteAbortedException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Hashtable;
@@ -771,9 +772,16 @@
isValid = true;
for (int i = 0; i < n; i++) {
String name = (String) stream.readObject();
- Object value = stream.readObject();
- if ( (value instanceof String) && (value.equals(NOT_SERIALIZED)))
- continue;
+ final Object value;
+ try {
+ value = stream.readObject();
+ } catch (WriteAbortedException wae) {
+ if (wae.getCause() instanceof NotSerializableException) {
+ // Skip non serializable attributes
+ continue;
+ }
+ throw wae;
+ }
attributes.put(name, value);
}
isValid = isValidSave;
@@ -871,9 +879,7 @@
try {
stream.writeObject(saveValues.get(i));
} catch (NotSerializableException e) {
- log.error(sm.getString("standardSession.notSerializable",saveNames.get(i), id), e);
- stream.writeObject(NOT_SERIALIZED);
- log.error(" storing attribute '" + saveNames.get(i)+ "' with value NOT_SERIALIZED");
+ log.error(sm.getString("standardSession.notSerializable", saveNames.get(i), id), e);
}
}
Index: java/org/apache/catalina/session/StandardSession.java
===================================================================
--- java/org/apache/catalina/session/StandardSession.java (revision 1703678)
+++ java/org/apache/catalina/session/StandardSession.java (working copy)
@@ -22,6 +22,7 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.io.WriteAbortedException;
import java.security.AccessController;
import java.security.Principal;
import java.security.PrivilegedAction;
@@ -113,6 +114,7 @@
// ----------------------------------------------------------- Constructors
+
/**
* Construct a new Session associated with the specified Manager.
*
@@ -141,14 +143,6 @@
/**
- * The dummy attribute value serialized when a NotSerializableException is
- * encountered in writeObject()
.
- */
- protected static final String NOT_SERIALIZED =
- "___NOT_SERIALIZABLE_EXCEPTION___";
-
-
- /**
* The collection of user data attributes associated with this Session.
*/
protected Map attributes = new ConcurrentHashMap<>();
@@ -1631,9 +1625,16 @@
isValid = true;
for (int i = 0; i < n; i++) {
String name = (String) stream.readObject();
- Object value = stream.readObject();
- if ((value instanceof String) && (value.equals(NOT_SERIALIZED)))
- continue;
+ final Object value;
+ try {
+ value = stream.readObject();
+ } catch (WriteAbortedException wae) {
+ if (wae.getCause() instanceof NotSerializableException) {
+ // Skip non serializable attributes
+ continue;
+ }
+ throw wae;
+ }
if (manager.getContext().getLogger().isDebugEnabled())
manager.getContext().getLogger().debug(" loading attribute '" + name +
"' with value '" + value + "'");
@@ -1709,18 +1710,11 @@
try {
stream.writeObject(saveValues.get(i));
if (manager.getContext().getLogger().isDebugEnabled())
- manager.getContext().getLogger().debug
- (" storing attribute '" + saveNames.get(i) +
- "' with value '" + saveValues.get(i) + "'");
+ manager.getContext().getLogger().debug(
+ " storing attribute '" + saveNames.get(i) + "' with value '" + saveValues.get(i) + "'");
} catch (NotSerializableException e) {
- manager.getContext().getLogger().warn
- (sm.getString("standardSession.notSerializable",
- saveNames.get(i), id), e);
- stream.writeObject(NOT_SERIALIZED);
- if (manager.getContext().getLogger().isDebugEnabled())
- manager.getContext().getLogger().debug
- (" storing attribute '" + saveNames.get(i) +
- "' with value NOT_SERIALIZED");
+ manager.getContext().getLogger()
+ .warn(sm.getString("standardSession.notSerializable", saveNames.get(i), id), e);
}
}
Index: test/org/apache/catalina/session/TestStandardSession.java
===================================================================
--- test/org/apache/catalina/session/TestStandardSession.java (revision 1703678)
+++ test/org/apache/catalina/session/TestStandardSession.java (working copy)
@@ -26,9 +26,7 @@
import java.util.Map;
import org.junit.Assert;
-import org.junit.Ignore;
import org.junit.Test;
-
import org.apache.catalina.Manager;
import org.apache.catalina.core.StandardContext;
@@ -93,19 +91,29 @@
}
+ /**
+ * See Bug 58284
+ */
@Test
- @Ignore // This currently fails on de-serialization - bug 58284
- public void testSerializationComplex01() throws Exception {
+ public void serializeSkipsNonSerializableAttributes() throws Exception {
+ final String nonSerializableKey = "nonSerializable";
+ final String nestedNonSerializableKey = "nestedNonSerializable";
+ final String serializableKey = "serializable";
+ final Object serializableValue = "foo";
StandardSession s1 = new StandardSession(TEST_MANAGER);
s1.setValid(true);
- Map value = new HashMap<>();
+ Map value = new HashMap<>();
value.put("key", new NonSerializable());
- s1.setAttribute("attr01", value);
+ s1.setAttribute(nestedNonSerializableKey, value);
+ s1.setAttribute(serializableKey, serializableValue);
+ s1.setAttribute(nonSerializableKey, new NonSerializable());
StandardSession s2 = serializeThenDeserialize(s1);
- validateSame(s1, s2, 0);
+ Assert.assertNull(s2.getAttribute(nestedNonSerializableKey));
+ Assert.assertNull(s2.getAttribute(nonSerializableKey));
+ Assert.assertEquals(serializableValue, s2.getAttribute(serializableKey));
}
@@ -142,4 +150,4 @@
private static class NonSerializable {
}
-}
+}
\ No newline at end of file