Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 337957 - Redundant caching call in DefaultOppositeEndFinder
Summary: Redundant caching call in DefaultOppositeEndFinder
Status: CLOSED FIXED
Alias: None
Product: OCL
Classification: Modeling
Component: Core (show other bugs)
Version: 3.1.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: OCL Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-23 05:36 EST by Axel Uhl CLA
Modified: 2011-05-27 03:13 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Axel Uhl CLA 2011-02-23 05:36:02 EST
What should have been a side effect free getter (getLoadedPackages()) performs a side effect on the packages member variable and redundantly calls cachePackage(...). This shouldn't be the case. The following patch fixes this:

@@ -130,14 +130,14 @@ public class DefaultOppositeEndFinder
 	}
 	
 	private Set<EPackage> getLoadedPackages() {
+		Set<EPackage> result = new HashSet<EPackage>();
 		for (Object key : registry.values()) {
 			// if it's not a package descriptor indicating a not yet loaded package, add it
 			if (key instanceof EPackage) {
-				packages.add((EPackage) key);
-				cachePackage((EPackage) key);
+				result.add((EPackage) key);
 			}
 		}
-		return packages;
+		return result;
 	}
 
 	protected DefaultOppositeEndFinder(Registry registry) {
Comment 1 Ed Willink CLA 2011-02-23 05:46:51 EST
+1

Since it's a simple private method, perhaps it could be flattened.
Comment 2 Axel Uhl CLA 2011-02-23 05:57:12 EST
Inlined as suggested and committed.
Comment 3 Ed Willink CLA 2011-05-27 03:13:39 EDT
Closing