Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 329453

Summary: Extensions for Resources (such as Templates / Extensions) aren't cached properly
Product: [Modeling] M2T Reporter: thomas_ <thomas.fischer.lgz>
Component: XpandAssignee: Karsten Thoms <karsten.thoms>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: karsten.thoms, thomas.fischer.lgz
Version: unspecifiedFlags: karsten.thoms: kepler+
Target Milestone: M4   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
Shows the contents of the cache and the corresponding break-point used to display them
none
Shows the two different ExecutionContextImpl-instances none

Description thomas_ CLA 2010-11-04 12:10:15 EDT
Build Identifier: 20100917-0705

The (Xpand)ExecutionContextImpl uses an internal map in order to cache extensions per resource (allExtensionsPerResource<key: theResource, value: allTheExtensionsInThatResource)>. Unfortunately null is (always) used as the key. Thus the mechanism doesn't work and the extensions are calculated every time.

Reason:
The method internalAllExtensions() calculates the extensions for a given resource and then calls currentResource() in order to retrieve the value of the key (which is then used to store the extensions in the cache). This call always returns null.

Underlying reason: Mix up of Execution-Context-Instances
The ExecutionContextImpl uses another cache "extensionsForNameAndTypesCache" to allow quick access to an extension for a specific type. This cache calls the internalAllResources method of the ExecutionContextImpl in case the right extensions haven't been cached yet. In order to be able to call that private method, the Cache holds an instance to the ExecutionContextImpl (the one it was created with). This instance doesn't change over time (as well as it's currentResource-attribute). (The cache itself is passed from ExecutionContextImpl to ExecutionContextImpl over time (cloneContext))
Please also see attached screenshots.
If you require further information, please feel free to contact me by email.

Reproducible: Always

Steps to Reproduce:
1. Download Eclipse with Modeling Tools (Build ID 20100917-0705)
2. Install the XPand-Plugins
3. Create the default project
4. Set this conditional breakpoint
_____________________________________________________________________________
System.err.println("all extensionsPerResource now contains: " + allExtensionsPerResource);
return false;
_____________________________________________________________________________

in Line 340 (return allExtensions) of the ExecutionContextImpl class
Comment 1 thomas_ CLA 2010-11-04 12:12:55 EDT
Created attachment 182392 [details]
Shows the contents of the cache and the corresponding break-point used to display them
Comment 2 thomas_ CLA 2010-11-04 12:15:37 EDT
Created attachment 182394 [details]
Shows the two different ExecutionContextImpl-instances

The current ExecutionContextImpl has ID 49 (see top right) and it's current resource is really the current resource (e.g. the template / extension).
The executionContext related to the cache has ID 18. It's current resource is null.
Comment 3 thomas_ CLA 2010-11-04 12:21:48 EDT
Quick-fix: Use the currentResource2 as key
Comment 4 Karsten Thoms CLA 2012-08-14 02:03:17 EDT
Confirmed and fixed.
Comment 5 Eclipse Webmaster CLA 2017-10-31 11:08:06 EDT
Requested via bug 522520.

-M.
Comment 6 Eclipse Webmaster CLA 2017-10-31 11:19:39 EDT
Requested via bug 522520.

-M.