diff options
author | Juuso Valli <juuso@vaadin.com> | 2014-09-13 15:19:55 +0300 |
---|---|---|
committer | Sauli Tähkäpää <sauli@vaadin.com> | 2014-09-15 14:24:11 +0300 |
commit | 22f09cfeafcae80a8660ac2dcbb3918597321187 (patch) | |
tree | d93d75bf9e25ad532e37791426a679998cb94d28 | |
parent | 4a60f1a712787cfdadeddef399d177b25806017e (diff) | |
download | vaadin-framework-22f09cfeafcae80a8660ac2dcbb3918597321187.tar.gz vaadin-framework-22f09cfeafcae80a8660ac2dcbb3918597321187.zip |
Improve proxy comparison support (#14639)
Change-Id: I114ea5bf9d55c78826c1163206caf585b96143ef
-rw-r--r-- | server/src/com/vaadin/server/AbstractClientConnector.java | 31 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/server/AbstractClientConnectorProxyHandlingTest.java | 50 |
2 files changed, 75 insertions, 6 deletions
diff --git a/server/src/com/vaadin/server/AbstractClientConnector.java b/server/src/com/vaadin/server/AbstractClientConnector.java index d8d0d5cbd9..1f13010638 100644 --- a/server/src/com/vaadin/server/AbstractClientConnector.java +++ b/server/src/com/vaadin/server/AbstractClientConnector.java @@ -1001,11 +1001,6 @@ public abstract class AbstractClientConnector implements ClientConnector, this.errorHandler = errorHandler; } - private AbstractClientConnector getInstance() { - // returns the underlying instance regardless of proxies - return this; - } - /* * (non-Javadoc) * @@ -1013,12 +1008,36 @@ public abstract class AbstractClientConnector implements ClientConnector, */ @Override public boolean equals(Object obj) { + if (this == obj) { + return true; + } + /* + * This equals method must return true when we're comparing an object to + * its proxy. This happens a lot with CDI (and possibly Spring) when + * we're injecting Components. See #14639 + */ if (obj instanceof AbstractClientConnector) { - return super.equals(((AbstractClientConnector) obj).getInstance()); + AbstractClientConnector connector = (AbstractClientConnector) obj; + return connector.isThis(this); } return false; } + /** + * For internal use only, may be changed or removed in future versions. + * <p> + * This method must be protected, because otherwise it will not be redefined + * by the proxy to actually be called on the underlying instance. + * <p> + * See #14639 + * + * @deprecated only defined for framework hacks, do not use. + */ + @Deprecated + protected boolean isThis(Object that) { + return this == that; + } + /* * (non-Javadoc) * diff --git a/server/tests/src/com/vaadin/server/AbstractClientConnectorProxyHandlingTest.java b/server/tests/src/com/vaadin/server/AbstractClientConnectorProxyHandlingTest.java new file mode 100644 index 0000000000..c15676c18e --- /dev/null +++ b/server/tests/src/com/vaadin/server/AbstractClientConnectorProxyHandlingTest.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.server; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +import org.junit.Assert; +import org.junit.Test; + +/** + * We test that AbstractClientConnector has a suitable isThis method which is + * needed to correctly perform an equals check between a proxy and it's + * underlying instance. + * + * @author Vaadin Ltd + */ +public class AbstractClientConnectorProxyHandlingTest { + + @Test + public void abstractClientConnectorTest() { + try { + Method method = AbstractClientConnector.class.getDeclaredMethod( + "isThis", Object.class); + int modifiers = method.getModifiers(); + if (Modifier.isFinal(modifiers) || !Modifier.isProtected(modifiers) + || Modifier.isStatic(modifiers)) { + Assert.fail("isThis has invalid modifiers, CDI proxies will not work."); + } + } catch (SecurityException e) { + // Ignore, no can do + } catch (NoSuchMethodException e) { + Assert.fail("isThis is missing, CDI proxies will not work."); + } + } + +} |