Fix RequestFactoryInterfaceValidator when analyzing interfaces with static initializers.
Resolves GWT issue 5481.
Patch by: bobv
Review by: rjrjr
Review at http://gwt-code-reviews.appspot.com/1056801
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9149 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidator.java b/user/src/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidator.java
index 4903bea..7195af0 100644
--- a/user/src/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidator.java
+++ b/user/src/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidator.java
@@ -286,6 +286,10 @@
@Override
public MethodVisitor visitMethod(int access, String name, String desc,
String signature, String[] exceptions) {
+ // Ignore initializers
+ if ("<clinit>".equals(name) || "<init>".equals(name)) {
+ return null;
+ }
RFMethod method = new RFMethod(name, desc);
method.setDeclaredStatic((access & Opcodes.ACC_STATIC) != 0);
method.setDeclaredSignature(signature);
diff --git a/user/test/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidatorTest.java b/user/test/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidatorTest.java
index 0b1bad7..75b4f50 100644
--- a/user/test/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidatorTest.java
+++ b/user/test/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidatorTest.java
@@ -21,17 +21,53 @@
import com.google.gwt.requestfactory.shared.ProxyFor;
import com.google.gwt.requestfactory.shared.Request;
import com.google.gwt.requestfactory.shared.RequestContext;
+import com.google.gwt.requestfactory.shared.RequestFactory;
import com.google.gwt.requestfactory.shared.Service;
import com.google.gwt.requestfactory.shared.SimpleRequestFactory;
import junit.framework.TestCase;
+import java.util.logging.Level;
import java.util.logging.Logger;
/**
* JRE tests for {@link RequestFactoryInterfaceValidator}.
*/
public class RequestFactoryInterfaceValidatorTest extends TestCase {
+ static class ClinitEntity {
+ static ClinitEntity request() {
+ return null;
+ }
+
+ Object OBJECT = new Object();
+
+ String getId() {
+ return null;
+ }
+
+ int getVersion() {
+ return 0;
+ }
+ }
+
+ @ProxyFor(ClinitEntity.class)
+ interface ClinitEntityProxy extends EntityProxy {
+ Object OBJECT = new Object();
+ }
+
+ @Service(ClinitEntity.class)
+ interface ClinitRequestContext extends RequestContext {
+ Object OBJECT = new Object();
+
+ Request<ClinitEntityProxy> request();
+ }
+
+ interface ClinitRequestFactory extends RequestFactory {
+ Object OBJECT = new Object();
+
+ ClinitRequestContext context();
+ }
+
static class Domain {
static int fooStatic(int a) {
return 0;
@@ -107,6 +143,14 @@
RequestFactoryInterfaceValidator v;
+ /**
+ * Ensure that the <clinit> methods don't interfere with validation.
+ */
+ public void testIntecfacesWithClinits() {
+ v.validateRequestFactory(ClinitRequestFactory.class.getName());
+ assertFalse(v.isPoisoned());
+ }
+
public void testMismatchedArity() {
v.validateRequestContext(ServiceRequestMismatchedArity.class.getName());
assertTrue(v.isPoisoned());
@@ -132,11 +176,6 @@
assertTrue(v.isPoisoned());
}
- public void testMissingServiceAnnotations() {
- v.validateRequestContext(RequestContextMissingAnnotation.class.getName());
- assertTrue(v.isPoisoned());
- }
-
public void testMissingIdAndVersion() {
v.validateEntityProxy(DomainProxy.class.getName());
assertTrue(v.isPoisoned());
@@ -147,6 +186,11 @@
assertTrue(v.isPoisoned());
}
+ public void testMissingServiceAnnotations() {
+ v.validateRequestContext(RequestContextMissingAnnotation.class.getName());
+ assertTrue(v.isPoisoned());
+ }
+
public void testOverloadedMethod() {
v.validateEntityProxy(DomainWithOverloadsProxy.class.getName());
assertTrue(v.isPoisoned());
@@ -163,6 +207,7 @@
@Override
protected void setUp() throws Exception {
Logger logger = Logger.getLogger("");
+ logger.setLevel(Level.OFF);
v = new RequestFactoryInterfaceValidator(logger, new ClassLoaderLoader(
Thread.currentThread().getContextClassLoader()));
}