Bug 569038

Summary: Ensure correct ownership of instances created with ContextInjectionFactory.make
Product: [Eclipse Project] Platform Reporter: Rolf Theunissen <rolf.theunissen>
Component: UIAssignee: Platform-UI-Inbox <Platform-UI-Inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3    
Version: 4.17   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on: 569439    
Bug Blocks:    

Description Rolf Theunissen CLA 2020-11-22 11:50:25 EST
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.