Re: (Server-side) AutoBeans and thread-safety

2015-03-04 Thread Andreas Kohn


On Tuesday, February 24, 2015 at 6:56:50 PM UTC+1, Andreas Kohn wrote:

 I understand that autobean's are actually parsed lazily, so for me this 
 looks like a concurrency issue somewhere inside the autobeans framework 
 itself. I didn't see any notes about sharing autobeans between threads in 
 the documentation, so:
 1. Should it be possible to share them, or is additional synchronization 
 in the application code needed? 
 2. Instead of synchronizing all accesses, would it be enough to force a 
 full parse run of the autobean before making it visible to other threads?
 3. Is this problem only affecting server-side code, or would similar 
 issues also be possible in client-side code? (I'm suspecting: It depends 
 on the browser's implementation of JS?)

 Regarding the second question: I did not manage to reproduce the issue by 
 using this additional code:
 AutoBeanUtils.getAutoBean(delegate).accept(new AutoBeanVisitor() { /* 
 Nothing */ });



Small update here: I was able to get my test to break again even after 
using the #accept() idea, by using a Map property in the bean, and 
iterating over its entry set. So my conclusion here: using autobeans on the 
server side without external synchronization and careful coding is 
dangerous. 

I've now worked around this issue by copying the contents of the bean into 
a separate class that implements the bean interface as well. In my case I 
do not need the ability to modify the contents, so I didn't bother working 
out how I'd get my copy serialized into JSON again.

Regards,
--
Andreas

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


(Server-side) AutoBeans and thread-safety

2015-02-24 Thread Andreas Kohn
Hi,

I hope this is the right forum to also ask questions about the Autobeans 
framework, if not please do redirect me!

We're using autobeans both in client code and server code, and so far 
things work nicely except in one situation: sometimes parsing autobeans 
simply fails with a stack trace similar to this:
java.lang.NullPointerException
at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.makeProxy(
ProxyAutoBean.java:105)
at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.createShim(
ProxyAutoBean.java:393)
at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.as(ProxyAutoBean.
java:222)
at com.google.web.bindery.autobean.vm.impl.ShimHandler.maybeWrap(ShimHandler
.java:113)
at com.google.web.bindery.autobean.vm.impl.ShimHandler.invoke(ShimHandler.
java:91)
at com.sun.proxy.$Proxy368.get(Unknown Source)
at com.google.web.bindery.autobean.shared.impl.SplittableSimpleMap$1$1$1.
init(SplittableSimpleMap.java:90)
at com.google.web.bindery.autobean.shared.impl.SplittableSimpleMap$1$1.next(
SplittableSimpleMap.java:86)
at com.google.web.bindery.autobean.shared.impl.SplittableSimpleMap$1$1.next(
SplittableSimpleMap.java:76)
at sun.reflect.GeneratedMethodAccessor89.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.google.web.bindery.autobean.vm.impl.ShimHandler.invoke(ShimHandler.
java:85)
at com.sun.proxy.$Proxy347.next(Unknown Source)
at XXX.function(XXX.java:...)

When dumping the contents of the bean at that point everything looks 
proper, and it can be parsed just fine in an isolated unit test. After some 
more investigation I managed to reproduce this and other similar 
exceptions: it seems to happen when multiple threads access a recently 
created autobean proxy.

I understand that autobean's are actually parsed lazily, so for me this 
looks like a concurrency issue somewhere inside the autobeans framework 
itself. I didn't see any notes about sharing autobeans between threads in 
the documentation, so:
1. Should it be possible to share them, or is additional synchronization in 
the application code needed? 
2. Instead of synchronizing all accesses, would it be enough to force a 
full parse run of the autobean before making it visible to other threads?
3. Is this problem only affecting server-side code, or would similar issues 
also be possible in client-side code? (I'm suspecting: It depends on the 
browser's implementation of JS?)

Regarding the second question: I did not manage to reproduce the issue by 
using this additional code:
AutoBeanUtils.getAutoBean(delegate).accept(new AutoBeanVisitor() { /* 
Nothing */ });

Regards,
--
Andreas

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.