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

Bug 331098

Summary: MemoryLeak in DefaultPersistenceProviderResolver
Product: z_Archived Reporter: Sahoo <sanjeeb.sahoo>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: critical    
Priority: P2 CC: patric, tom.ware, vikram.jeet.bhatia
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed Fix none

Description Sahoo CLA 2010-11-25 04:40:00 EST
Build Identifier: 2.2.0.v20101117-r8503

DefaultPersistenceProviderResolver has field like this:

        private volatile WeakHashMap<ClassLoader, List<PersistenceProvider>> providers = new WeakHashMap<ClassLoader, List<PersistenceProvider>>();
        ...
                        Collection<ProviderName> providerNames = getProviderNames(loader);
                loadedProviders = new ArrayList<PersistenceProvider>();
        ...
A WeakHashMap is used to avoid permanently holding a reference to user's class loader, but look at the value being stored there: it's an ArrayList<PersistenceProvider>, which means if the provider is loaded by user's class loader, it can never be garbage collected until the cache is cleared. Does anyone clear this cache? I don't think so. Why not change it to:
WeakHashMap<ClassLoader, List<String>>, where in the value, we store discovered provider class names as opposed to provider instances. When a provider is required, one can then do ClassLoader.loadClass(providerName).newInstance().

Reproducible: Always
Comment 1 Tom Ware CLA 2010-12-09 09:04:24 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 2 Vikram Bhatia CLA 2012-11-06 11:01:32 EST
Created attachment 223245 [details]
Proposed Fix
Comment 3 Vikram Bhatia CLA 2012-11-07 12:37:57 EST
Fixed in EclipseLink 2.5.0 with Commit Id - dd616647431960dd929a6bc7bff54a71f988a7c1
Comment 4 Vikram Bhatia CLA 2012-11-07 23:57:57 EST
Fixed in EclipseLink 2.4.2 with Commit Id - 645725ff8cfa0e8b3c4e2f934aa1669aef07d103
Comment 5 Tom Ware CLA 2012-12-07 07:32:34 EST
*** Bug 353155 has been marked as a duplicate of this bug. ***
Comment 6 Patric Rufflar CLA 2012-12-07 08:26:42 EST
Will this bug be officially announced that all JEE container vendors are aware that they have to update their javax.persistence.jar?

Will the official JSR 317/338 JPA spec jars be updated accordingly?
( http://download.oracle.com/otndocs/jcp/persistence-2.0-fr-eval-oth-JSpec/ )

Otherwise this bugfix might not make into the application server's code - and chances are high that the leak will stay in these environments.
Comment 7 Eclipse Webmaster CLA 2022-06-09 10:17:10 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 8 Eclipse Webmaster CLA 2022-06-09 10:33:13 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink