summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Paul <henrik@vaadin.com>2013-10-18 15:06:03 +0300
committerHenrik Paul <henrik@vaadin.com>2013-10-18 15:06:03 +0300
commitdf3d643b3aaa3112d59e2ae0fb3649dd37e927a7 (patch)
tree481b2eb92e88dcb977a68b3f4d74d8caa5ed828a
parent85251833de3bd101d388b20fdb9b02c532a9f1c9 (diff)
parentebdc3652764e8ec2ce292879d459a8d0c6c2d2e3 (diff)
downloadvaadin-framework-df3d643b3aaa3112d59e2ae0fb3649dd37e927a7.tar.gz
vaadin-framework-df3d643b3aaa3112d59e2ae0fb3649dd37e927a7.zip
Merge commit 'ebdc3652764e8ec2ce292879d459a8d0c6c2d2e3'
Conflicts: server/src/com/vaadin/server/VaadinSession.java Change-Id: I51383060a95354b7ffbcc5b12683c1d1a817b8bf
-rw-r--r--server/src/com/vaadin/server/VaadinSession.java27
-rw-r--r--server/tests/src/com/vaadin/tests/server/TestSerialization.java19
2 files changed, 34 insertions, 12 deletions
diff --git a/server/src/com/vaadin/server/VaadinSession.java b/server/src/com/vaadin/server/VaadinSession.java
index 8f15dacc98..89259c53ca 100644
--- a/server/src/com/vaadin/server/VaadinSession.java
+++ b/server/src/com/vaadin/server/VaadinSession.java
@@ -16,6 +16,8 @@
package com.vaadin.server;
+import java.io.IOException;
+import java.io.ObjectInputStream;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Collection;
@@ -202,10 +204,10 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
* session is serialized as long as it doesn't happen while some other
* thread has the lock.
*/
- private transient ConcurrentLinkedQueue<FutureAccess> pendingAccessQueue;
+ private transient ConcurrentLinkedQueue<FutureAccess> pendingAccessQueue = new ConcurrentLinkedQueue<FutureAccess>();
/**
- * Create a new service session tied to a Vaadin service
+ * Creates a new VaadinSession tied to a VaadinService.
*
* @param service
* the Vaadin service for the new session
@@ -1260,18 +1262,15 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
}
/**
- * Gets the queue of tasks submitted using {@link #access(Runnable)}.
+ * Gets the queue of tasks submitted using {@link #access(Runnable)}. It is
+ * safe to call this method and access the returned queue without holding
+ * the {@link #lock() session lock}.
*
* @since 7.1
*
- * @return the pending access queue
+ * @return the queue of pending access tasks
*/
public Queue<FutureAccess> getPendingAccessQueue() {
- if (pendingAccessQueue == null) {
- // pendingAccessQueue is transient, so will be null after
- // deserialization
- pendingAccessQueue = new ConcurrentLinkedQueue<FutureAccess>();
- }
return pendingAccessQueue;
}
@@ -1288,6 +1287,16 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
}
/**
+ * Override default deserialization logic to account for transient
+ * {@link #pendingAccessQueue}.
+ */
+ private void readObject(ObjectInputStream stream) throws IOException,
+ ClassNotFoundException {
+ stream.defaultReadObject();
+ pendingAccessQueue = new ConcurrentLinkedQueue<FutureAccess>();
+ }
+
+ /**
* Finds the UI with the corresponding embed id.
*
* @since 7.2
diff --git a/server/tests/src/com/vaadin/tests/server/TestSerialization.java b/server/tests/src/com/vaadin/tests/server/TestSerialization.java
index 84ff5ad6fa..a52821a919 100644
--- a/server/tests/src/com/vaadin/tests/server/TestSerialization.java
+++ b/server/tests/src/com/vaadin/tests/server/TestSerialization.java
@@ -14,6 +14,7 @@ import com.vaadin.data.Property;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.data.util.MethodProperty;
import com.vaadin.data.validator.RegexpValidator;
+import com.vaadin.server.VaadinSession;
import com.vaadin.ui.Form;
public class TestSerialization extends TestCase {
@@ -21,7 +22,7 @@ public class TestSerialization extends TestCase {
public void testValidators() throws Exception {
RegexpValidator validator = new RegexpValidator(".*", "Error");
validator.validate("aaa");
- RegexpValidator validator2 = (RegexpValidator) serializeAndDeserialize(validator);
+ RegexpValidator validator2 = serializeAndDeserialize(validator);
validator2.validate("aaa");
}
@@ -67,7 +68,17 @@ public class TestSerialization extends TestCase {
serializeAndDeserialize(mp);
}
- private static Serializable serializeAndDeserialize(Serializable s)
+ public void testVaadinSession() throws Exception {
+ VaadinSession session = new VaadinSession(null);
+
+ session = serializeAndDeserialize(session);
+
+ assertNotNull(
+ "Pending access queue was not recreated after deserialization",
+ session.getPendingAccessQueue());
+ }
+
+ private static <S extends Serializable> S serializeAndDeserialize(S s)
throws IOException, ClassNotFoundException {
// Serialize and deserialize
@@ -77,10 +88,12 @@ public class TestSerialization extends TestCase {
byte[] data = bs.toByteArray();
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(
data));
- Serializable s2 = (Serializable) in.readObject();
+ @SuppressWarnings("unchecked")
+ S s2 = (S) in.readObject();
// using special toString(Object) method to avoid calling
// Property.toString(), which will be temporarily disabled
+ // TODO This is hilariously broken (#12723)
if (s.equals(s2)) {
System.out.println(toString(s) + " equals " + toString(s2));
} else {