The attached project (maven and intellij) exhibits the problem with private
observer methods when an App scoped bean is decorated.
You can rung it from IJ, or from the command line using: mvn compile
exec:java -Dexec.mainClass=Main
As delivered, you should see output like the following:
doSomething decorator,
delegate=org.jboss.weld.proxies.AppScopeBean$Proxy$_$$_WeldSubclass@4550bb58
<mailto:delegate=org.jboss.weld.proxies.AppScopeBean$Proxy$_$$_WeldSubclass@
4550bb58>
doSomething,
this=org.jboss.weld.proxies.AppScopeBean$Proxy$_$$_WeldSubclass@4550bb58
<mailto:this=org.jboss.weld.proxies.AppScopeBean$Proxy$_$$_WeldSubclass@4550
bb58> , anInt=5
Got event,
this=org.jboss.weld.proxies.AppScopeBean$Proxy$_$$_Weld$Proxy$@49139829
<mailto:this=org.jboss.weld.proxies.AppScopeBean$Proxy$_$$_Weld$Proxy$@49139
829> <= should be
org.jboss.weld.proxies.AppScopeBean$Proxy$_$$_WeldSubclass
Got event, anInt=0 <= should be 5
Note the "anInt=0" where it should be 5. If you change
AppScopeBean#observer from 'private' to 'protected' you will see output
like
this:
doSomething decorator,
delegate=org.jboss.weld.proxies.AppScopeBean$Proxy$_$$_WeldSubclass@4550bb58
<mailto:delegate=org.jboss.weld.proxies.AppScopeBean$Proxy$_$$_WeldSubclass@
4550bb58>
doSomething,
this=org.jboss.weld.proxies.AppScopeBean$Proxy$_$$_WeldSubclass@4550bb58
<mailto:this=org.jboss.weld.proxies.AppScopeBean$Proxy$_$$_WeldSubclass@4550
bb58> , anInt=5
Got event,
this=org.jboss.weld.proxies.AppScopeBean$Proxy$_$$_WeldSubclass@4550bb58
<mailto:this=org.jboss.weld.proxies.AppScopeBean$Proxy$_$$_WeldSubclass@4550
bb58> <= should be
org.jboss.weld.proxies.AppScopeBean$Proxy$_$$_WeldSubclass
Got event, anInt=5 <= should be 5
Note that in the latter case, the member variable is properly initialized.
The problem stems from the fact that the proxy implementation doesn't
include the private methods. I think that the changes included in
https://issues.jboss.org/browse/WELD-2092 have broken decorated beans with
private observer methods. It also hinders tests that use things like JMockit
Deencapsulation to invoke private methods on bean instances.
I don't know how this all reconciles with the CDI spec, but the current
implementation seems broken if I can't have a private observer method simply
because the class is the target of a Decorator.
Thanks for taking the time to review this post.
Larry.