summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/server/AbstractClientConnector.java2
-rw-r--r--server/src/com/vaadin/server/VaadinSession.java11
-rw-r--r--server/src/com/vaadin/ui/ConnectorTracker.java3
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java2
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java1
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java5
6 files changed, 19 insertions, 5 deletions
diff --git a/server/src/com/vaadin/server/AbstractClientConnector.java b/server/src/com/vaadin/server/AbstractClientConnector.java
index 4c22a96782..2fb468bd1c 100644
--- a/server/src/com/vaadin/server/AbstractClientConnector.java
+++ b/server/src/com/vaadin/server/AbstractClientConnector.java
@@ -146,6 +146,8 @@ public abstract class AbstractClientConnector implements ClientConnector {
}
protected SharedState getState() {
+ assert getSession() == null
+ || getSession().getLock().isHeldByCurrentThread() : VaadinSession.SESSION_LOCK_MESSAGE;
if (null == sharedState) {
sharedState = createState();
}
diff --git a/server/src/com/vaadin/server/VaadinSession.java b/server/src/com/vaadin/server/VaadinSession.java
index a91c011ddf..03e6420008 100644
--- a/server/src/com/vaadin/server/VaadinSession.java
+++ b/server/src/com/vaadin/server/VaadinSession.java
@@ -28,7 +28,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
@@ -71,6 +70,8 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
*/
public static final String UI_PARAMETER = "UI";
+ public static final String SESSION_LOCK_MESSAGE = "You are accessing UI state without proper synchronization!";
+
private static final Method BOOTSTRAP_FRAGMENT_METHOD = ReflectTools
.findMethod(BootstrapListener.class, "modifyBootstrapFragment",
BootstrapFragmentResponse.class);
@@ -78,7 +79,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
.findMethod(BootstrapListener.class, "modifyBootstrapPage",
BootstrapPageResponse.class);
- private final Lock lock = new ReentrantLock();
+ private final ReentrantLock lock = new ReentrantLock();
/**
* An event sent to {@link #start(SessionStartEvent)} when a new Application
@@ -206,6 +207,10 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
private final Map<String, Object> attributes = new HashMap<String, Object>();
+ public VaadinSession() {
+ // TODO Auto-generated constructor stub
+ }
+
/**
* @see javax.servlet.http.HttpSessionBindingListener#valueBound(HttpSessionBindingEvent)
*/
@@ -1304,7 +1309,7 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
*
* @return the lock that should be used for synchronization
*/
- public Lock getLock() {
+ public ReentrantLock getLock() {
return lock;
}
diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java
index d454df98ee..dbada63a47 100644
--- a/server/src/com/vaadin/ui/ConnectorTracker.java
+++ b/server/src/com/vaadin/ui/ConnectorTracker.java
@@ -29,6 +29,7 @@ import com.vaadin.server.AbstractClientConnector;
import com.vaadin.server.AbstractCommunicationManager;
import com.vaadin.server.ClientConnector;
import com.vaadin.server.GlobalResourceHandler;
+import com.vaadin.server.VaadinSession;
/**
* A class which takes care of book keeping of {@link ClientConnector}s for a
@@ -286,6 +287,8 @@ public class ConnectorTracker implements Serializable {
* The connector that should be marked clean.
*/
public void markDirty(ClientConnector connector) {
+ assert uI.getSession() == null
+ || uI.getSession().getLock().isHeldByCurrentThread() : VaadinSession.SESSION_LOCK_MESSAGE;
if (isWritingResponse()) {
throw new IllegalStateException(
"A connector should not be marked as dirty while a response is being written.");
diff --git a/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java b/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java
index b64514ea14..bc5846acf0 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java
@@ -69,6 +69,7 @@ public class ConverterFactory extends TestCase {
final VaadinSession appWithCustomIntegerConverter = new VaadinSession();
appWithCustomIntegerConverter
.setConverterFactory(new ConverterFactory42());
+ appWithCustomIntegerConverter.getLock().lock();
TextField tf = new TextField("", "123") {
@Override
@@ -97,6 +98,7 @@ public class ConverterFactory extends TestCase {
public void testApplicationConverterFactoryForDifferentThanCurrentApplication() {
final VaadinSession fieldAppWithCustomIntegerConverter = new VaadinSession();
+ fieldAppWithCustomIntegerConverter.getLock().lock();
fieldAppWithCustomIntegerConverter
.setConverterFactory(new ConverterFactory42());
VaadinSession.setCurrent(new VaadinSession());
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java
index b48ad62bcc..031e0c80bd 100644
--- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java
@@ -187,6 +187,7 @@ public class AbstractFieldValueConversions extends TestCase {
public void testNumberDoubleConverterChange() {
final VaadinSession a = new VaadinSession();
+ a.getLock().lock();
VaadinSession.setCurrent(a);
TextField tf = new TextField() {
@Override
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java
index c9f579a887..f259e156ff 100644
--- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java
@@ -19,10 +19,11 @@ public class RemoveListenersOnDetach {
AbstractField field = new AbstractField() {
final private VaadinSession application = new VaadinSession() {
-
+ {
+ getLock().lock();
+ }
};
private UI uI = new UI() {
-
@Override
protected void init(WrappedRequest request) {