Skip to content

Commit 0ea24c6

Browse files
committed
HHH-8225 EMF cannot be created, closed, then re-created in OSGi
Conflicts: hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiClassLoader.java hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiPersistenceProvider.java
1 parent 8e3fd81 commit 0ea24c6

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

hibernate-osgi/src/main/java/org/hibernate/osgi/OsgiClassLoader.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
import java.util.ArrayList;
2828
import java.util.Enumeration;
2929
import java.util.HashMap;
30+
import java.util.HashSet;
3031
import java.util.List;
3132
import java.util.Map;
3233
import java.util.NoSuchElementException;
34+
import java.util.Set;
3335

3436
import org.osgi.framework.Bundle;
3537

@@ -41,16 +43,14 @@
4143
* @author Tim Ward
4244
*/
4345
public class OsgiClassLoader extends ClassLoader {
46+
// Leave these as Sets -- addClassLoader or addBundle may be called more
47+
// than once if a SF or EMF is closed and re-created.
48+
private Set<ClassLoader> classLoaders = new HashSet<ClassLoader>();
49+
private Set<Bundle> bundles = new HashSet<Bundle>();
4450

45-
private List<ClassLoader> classLoaders = new ArrayList<ClassLoader>();
46-
47-
private List<Bundle> bundles = new ArrayList<Bundle>();
48-
4951
private Map<String, Class<?>> classCache = new HashMap<String, Class<?>>();
5052

5153
private Map<String, URL> resourceCache = new HashMap<String, URL>();
52-
53-
private Map<String, Enumeration<URL>> resourceListCache = new HashMap<String, Enumeration<URL>>();
5454

5555
/**
5656
* Load the class and break on first found match.
@@ -132,16 +132,15 @@ protected URL findResource(String name) {
132132

133133
/**
134134
* Load the class and break on first found match.
135+
*
136+
* Note: Since they're Enumerations, do not cache these results!
137+
*
135138
* TODO: Should this throw a different exception or warn if multiple
136139
* classes were found? Naming collisions can and do happen in OSGi...
137140
*/
138141
@SuppressWarnings("unchecked")
139142
@Override
140143
protected Enumeration<URL> findResources(String name) {
141-
if ( resourceListCache.containsKey( name ) ) {
142-
return resourceListCache.get( name );
143-
}
144-
145144
final List<Enumeration<URL>> enumerations = new ArrayList<Enumeration<URL>>();
146145

147146
for ( Bundle bundle : bundles ) {
@@ -188,8 +187,6 @@ public URL nextElement() {
188187
}
189188
};
190189

191-
resourceListCache.put( name, aggEnumeration );
192-
193190
return aggEnumeration;
194191
}
195192

@@ -204,7 +201,6 @@ public void addBundle( Bundle bundle ) {
204201
public void clear() {
205202
classCache.clear();
206203
resourceCache.clear();
207-
resourceListCache.clear();
208204
}
209205

210206
}

0 commit comments

Comments
 (0)