Tobias Stoeckmann created OWB-1013:
--------------------------------------

             Summary: Race condition in Instance injection
                 Key: OWB-1013
                 URL: https://issues.apache.org/jira/browse/OWB-1013
             Project: OpenWebBeans
          Issue Type: Bug
          Components: Injection and Lookup
    Affects Versions: 1.2.6
            Reporter: Tobias Stoeckmann


OpenWebBeans is prone to flip instances of javax.enterprise.inject.Instance in 
multi-threaded environments.

It is possible for multiple threads to access InstanceProducer at the same time 
with the same creational context. If that happens, it is not verified that 
these threads get the correct injectionPoint out of the injectionPoints stack 
in the shared CreationalContextImpl.

Please see attached example source (with comments included). It'll require a 
debugger because it's quite tricky to get the threads into proper timing. Start 
main method of class de.cewe.race.Main. It constructs a simple SE container and 
executes two threads which will trigger the issue.

Set breakpoints at:
- de.cewe.race.CDIMain, line 46 (System.out.println)
- org.apache.webbeans.portable.InstanceProducer, line 65 (getInjectionPoint)

Wait until threads "RunnableA" and "RunnableB" reached the second breakpoint. 
Then let RunnableA finish. It will trigger a ClassCastException. For your own 
convenience, activate the second breakpoint after first one is reached. It 
reduces debugger noise during startup.


Sep 26, 2014 10:36:53 AM org.apache.webbeans.lifecycle.AbstractLifeCycle 
bootstrapApplication
INFORMATION: OpenWebBeans Container is starting...
Sep 26, 2014 10:36:53 AM 
org.apache.webbeans.corespi.scanner.AbstractMetaDataDiscovery 
addWebBeansXmlLocation
INFORMATION: added beans.xml marker: 
file:/C:/Users/Stoeckmann/workspace/instance-race/target/classes/META-INF/beans.xml
Sep 26, 2014 10:36:53 AM org.apache.webbeans.config.BeansDeployer 
validateInjectionPoints
INFORMATION: All injection points were validated successfully.
Sep 26, 2014 10:36:53 AM org.apache.webbeans.lifecycle.AbstractLifeCycle 
bootstrapApplication
INFORMATION: OpenWebBeans Container has started, it took [213] ms.
don't forget to activate your breakpoint!
Master A: de.cewe.race.a.MasterA@53aaed7
Exception in thread "RunnableA" java.lang.ClassCastException: 
de.cewe.race.b.SlaveB cannot be cast to de.cewe.race.a.SlaveA
        at de.cewe.race.a.MasterA.access(MasterA.java:11)
        at de.cewe.race.a.RunnableA.run(RunnableA.java:13)
        at java.lang.Thread.run(Thread.java:745)
Master B: de.cewe.race.b.MasterB@662546db
Exception in thread "RunnableB" java.lang.ClassCastException: 
de.cewe.race.a.MasterA cannot be cast to de.cewe.race.b.SlaveB
        at de.cewe.race.b.MasterB.access(MasterB.java:11)
        at de.cewe.race.b.RunnableB.run(RunnableB.java:13)
        at java.lang.Thread.run(Thread.java:745)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to