Community
Participate
Working Groups
At least in two testsuites instability was caused by premature garbage collection of instances created with ContextInjectionFactory.make, see Bug 551744 and Bug 566172. By default, instances created with this factory are only referenced by weak references in the context. Therefore they can be garbage collected at any time, resulting in unexpected behavior. This can also happen in production code. Correct ownership of these instances must be validated. There are different strategies used now: 1. The caller of ContextInjectionFactory.make has a field reference to the result 2. The caller of ContextInjectionFactory.make adds the result to the context 3. The @PostConstruct method in the instance created adds itself to the context 4. No (non-weak) reference to the instance. The 4th strategy was the root cause of the bugs mentioned above. To me, the first two strategies or correct. The 3rd feels as if control is reverted, and therefore a any-pattern. The 4th should not be used, unless the instance is never to be referenced. All code should be reviewed on the use of this factory. Also, the documentation of ContextInjectionFactory.make could be made more clear to emphasize that the created instance is not (non-weak) referenced.