Bug 569038 - Ensure correct ownership of instances created with ContextInjectionFactory.make
Summary: Ensure correct ownership of instances created with ContextInjectionFactory.make
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.17   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 569439
Blocks:
  Show dependency tree
 
Reported: 2020-11-22 11:50 EST by Rolf Theunissen CLA
Modified: 2020-12-03 14:05 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.