google-code-export / gwt-test-utils

Automatically exported from code.google.com/p/gwt-test-utils
1 stars 0 forks source link

LocalizableCreateHandler not handling abstract classes #59

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
LocalizableCreateHandler does not handle GWT's localizable type, if the type is 
other than an interface.
The reason is the use of jlr.Proxy, which only takes interfaces.

Reproduction:
1. Have an (abstract) class extending com.google.gwt.i18n.client.Messages 
2. Have some place where the class is instantiated using GWT.create()
3. Write a test that executes the above code.

//--- Example classes ---//
public abstract class MyMessages implements Messages {
}

public class AbstractMessages {
    public AbstractMessages() {
        GWT.create(MyMessages.class);
    }
}

//--- Test class ---//
public class AbstractMessagesTest extends GwtTest {

    @Override
    public String getModuleName() {
        return "app.Main";
  }

    @Test
    public void test() {
        final AbstractMessages test = new AbstractMessages();
        Assert.assertNotNull(test);
    }
}

//--- Thrown Exception ---//
com.octo.gwt.test.exceptions.GwtTestPatchException: Error while creation 
instance of 'app.client.AbstractMessages$MyMessages' through 
'com.octo.gwt.test.internal.utils.i18n.LocalizableCreateHandler' instance
    at com.octo.gwt.test.internal.patchers.GwtPatcher.create(GwtPatcher.java:30)
    at com.google.gwt.core.client.GWT.create(GWT.java)
    at app.client.AbstractMessages.<init>(AbstractMessages.java:9)
    at app.client.AbstractMessagesTest.test(AbstractMessagesTest.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at com.octo.gwt.test.internal.runner.AbstractGwtRunner.run(AbstractGwtRunner.java:40)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:199)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.IllegalArgumentException: 
app.client.AbstractMessages$MyMessages is not an interface
    at java.lang.reflect.Proxy.getProxyClass(Proxy.java:362)
    at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
    at com.octo.gwt.test.internal.utils.i18n.LocalizableCreateHandler$LocalizableResourceProxyFactory.createProxy(LocalizableCreateHandler.java:55)
    at com.octo.gwt.test.internal.utils.i18n.LocalizableCreateHandler.create(LocalizableCreateHandler.java:79)
    at com.octo.gwt.test.internal.patchers.GwtPatcher.create(GwtPatcher.java:22)
    ... 33 more

System:
Windows 7
GWT 2.2.0
gwt-test-utils-0.28.5.jar

Original issue reported on code.google.com by stefan.s...@googlemail.com on 2 Aug 2011 at 10:34

GoogleCodeExporter commented 9 years ago

Original comment by gael.laz...@gmail.com on 2 Aug 2011 at 10:37

GoogleCodeExporter commented 9 years ago

Original comment by gael.laz...@gmail.com on 6 Aug 2011 at 7:41

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I wrote my own abstract class to test if your code would work during a real GWT 
module load.

So, my abstract class which implements Messages :

  public abstract class AbstractMessage implements Messages {

  }

And the onModuleLoad code :

  public void onModuleLoad() {

    AbstractMessage abstractMessage = GWT.create(AbstractMessage.class);
    System.out.println(abstractMessage);
  }

GWT Debug output :

[DEBUG] [test_messages] - Rebinding com.glz.client.AbstractMessage
[DEBUG] [test_messages] - Invoking generator 
com.google.gwt.i18n.rebind.LocalizableGenerator
[ERROR] [test_messages] - AbstractMessage must be an interface

The module failed to load. 

This explains why gwt-test-utils is expecting an interface instead of a class, 
regardless of how gwt-test-utils would implements the Messages subinterface.

Indeed, I have improved the message stack trace, you will not see the

Caused by: java.lang.IllegalArgumentException: CustomAbstractClass is not an 
interface
    at java.lang.reflect.Proxy.getProxyClass(Proxy.java:362)

anymore. Instead of that, a GwtTestI18NException will be thrown with the same 
message as GWT :  'AbstractMessage must be an interface'.
I've deployed new 0.32-SNAPSHOT, 0.22.3-SNAPSHOT, 0.25.3-SNAPSHOT and 
0.28.6-SNAPSHOT with this improvement. 

But I may have missed/misunderstood something about your problem.. If so, could 
you be more specific ?

Original comment by gael.laz...@gmail.com on 6 Aug 2011 at 8:37

GoogleCodeExporter commented 9 years ago
Actually, the MyMessages was created with a customised Generator declared in 
.ui.xml.

LocalizableGenerator cannot generate instance for classes, only for interfaces.

Original comment by gael.laz...@gmail.com on 8 Aug 2011 at 9:55