AutoBean

391 views
Skip to first unread message

Aidan O'Kelly

unread,
Oct 17, 2011, 2:38:53 PM10/17/11
to google-we...@googlegroups.com
Is anyone using AutoBean in a JRE environment successfully? When trying a very simple test I get a NPE when I try to use AutoBeanCodex.encode(myAutoBean) 

My Bean interfaces look like this:

public static interface Point {
Long getX();
Long getY();
void setX(Long x);
void setY(Long y);
}
public static interface PointList  {
String getName();
void setName(String name);
List<Point> getPoints();
void setPoints(List<Point> points);
}

I'll omit the implementations for brevity but they are just standard objects with some getters/setters. 

My bean factory: 

public static interface MyFactory extends AutoBeanFactory { 
AutoBean<Point> point();
AutoBean<Point> point(Point instance);
AutoBean<PointList> pointList();
AutoBean<PointList> pointList(PointList instance);
}

I can create the AutoBean<Point> , AutoBean<PointList> ok from my factory. 
I can use AutoBeanCodex to encode a Point, and it emits the correct Json. 

If I try an encode a PointList object however, AutoBeanCodex.encode() throws a NPE. Its certainly the List<Point> which is causing it, as if I remove it, it works ok. And If I make PointList contain a few direct references to Point beans, that also works (so if PointList has  'Point getPointA()', 'Point getPointB()', it does encode everything correctly.)

Am I missing something obvious? The code to test is below.

public void listtest() {
Point o = new PointImpl();
Point n = new PointImpl();
PointList plist = new PointListImpl();
List<Point> points = new ArrayList<Point>();
o.setX(20L); o.setY(30L);
n.setY(60L); n.setX(80L);
points.add(o);
points.add(n);
plist.setName("OH");
plist.setPoints(points);
MyFactory fact = AutoBeanFactorySource.create(MyFactory.class);
AutoBean<PointList> alist = fact.pointList(plist);
System.out.println("Splittable Payload:" + AutoBeanCodex.encode(alist).getPayload()); 
}


java.lang.NullPointerException
at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl.doEncode(AutoBeanCodexImpl.java:558)
at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl$ObjectCoder.encode(AutoBeanCodexImpl.java:321)
at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl$CollectionCoder.encode(AutoBeanCodexImpl.java:163)
at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl$PropertyGetter.encodeProperty(AutoBeanCodexImpl.java:413)
at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl$PropertyGetter.visitReferenceProperty(AutoBeanCodexImpl.java:389)
at com.google.web.bindery.autobean.shared.AutoBeanVisitor.visitCollectionProperty(AutoBeanVisitor.java:229)
at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.traverseProperties(ProxyAutoBean.java:300)
at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.traverse(AbstractAutoBean.java:166)
at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.accept(AbstractAutoBean.java:101)
at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl.doEncode(AutoBeanCodexImpl.java:558)
at com.google.web.bindery.autobean.shared.AutoBeanCodex.encode(AutoBeanCodex.java:83)
at temp.AutoBeanListTest.listtest(AutoBeanListTest.java:111)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)




italobb

unread,
Apr 11, 2012, 10:10:40 AM4/11/12
to google-we...@googlegroups.com
I'm experiencing the same problem. Have you solved it? How? 

govindan govindan

unread,
Apr 20, 2012, 10:28:32 AM4/20/12
to google-we...@googlegroups.com

Hi,
 
Create the factory instance at the starting of the method similar to below
 
public void listtest(){
MyFactory fact = GWT.create(MyFactory.class); 
...

}

 
Use the below code

points.add(fact.point(o).as());

points.add(fact.point(n).as());

instead of

points.add(o);

points.add(n);
 
Thanks
Govindan

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/YcbECPWd-v4J.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Aidan O'Kelly

unread,
Apr 21, 2012, 2:08:00 PM4/21/12
to google-we...@googlegroups.com
Ta for posting the work-around.. I missed the original reply the my original thread (subscribed too many lists!) but for reference, there is a bug entry in the issues list for this: 
Reply all
Reply to author
Forward
0 new messages