| Summary: | Unguarded access to static map in ThemeManager could lead to application crash | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [RT] RAP | Reporter: | Stefan Röck <stefan.roeck> | ||||
| Component: | RWT | Assignee: | Project Inbox <rap-inbox> | ||||
| Status: | RESOLVED FIXED | QA Contact: | |||||
| Severity: | blocker | ||||||
| Priority: | P3 | ||||||
| Version: | 1.3 | ||||||
| Target Milestone: | 1.3 M3 | ||||||
| Hardware: | All | ||||||
| OS: | All | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
|
Description
Stefan Röck
Thanks for pointing this problem out, it must have been hard to find! Apart from the problematic modification of the adapters map in ThemeManager#getThemeAdapter, the map access doesn't need to be synchronized because the theme adapters are registered at application startup and the map is not modified after initialization. Since this map modification in ThemeManager#getThemeAdapter is a questionable optimization anyway, I leave this line of code out instead of synchronizing map access. The fix is in CVS HEAD. Created attachment 149421 [details]
Testcase for performance impacts
I wrote a test to measure the performance impacts.
Removing the put-call to the map leads to approx. 30% longer runtime of ThemeManager#getThemeAdapter. As this method is called quite often, this might be worth some investigation.
Using Collections.synchronizedMap() maybe helps. However, I'm satisfied with the proposed fix ;-)
Yes you may be right. But since the performance penalty affects only custom widgets, and synchronization also affects performance, I was not convinced that synchronizing the map access is necessarily better. I think only a profiler can tell us whether this change has a real performance impact or not. However, theme adapters should rather be resolved using an adapter factory (see bug 292362). So we should look into performance after this change. This affects all Widgets that are inherited from Control or Composite. If you mean those with "Custom widgets", I agree. I made some performance investigations using JProfiler with the result that leaving the "put" or adding synchronization around the "put" has nearly the same impact. However, of course this depends on how often the map is changed, how many threads are accessing, etc. (In reply to comment #4) > This affects all Widgets that are inherited from Control or Composite. If you > mean those with "Custom widgets", I agree. No this should only affect widgets that have not registered a theme adapter of their own. I think this affects all inherited widgets whose base widgets get a ThemeAdapter. For instance in Control#getBackground() the ThemeAdapter for the current control class is fetched, which applies for all inherited classes for Control. The same applies for Shell (Shell#getShellThemeAdapter()) although its not recommended to subclass Shell. |