NPE in SearchFactory while using different threads
--------------------------------------------------
Key: HSEARCH-21
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-21
Project: Hibernate Search
Type: Bug
Components: engine
Reporter: Sylvain Vieujot
java.lang.NullPointerException
at org.hibernate.search.SearchFactory.getSearchFactory(SearchFactory.java:120)
at com.seanergie.persistence.SessionsManager.getSearchFactory(SessionsManager.java:374)
...
The contexts ThreadLocal is missing a get method. it is initialized by the first thread
that uses it by the static statement, but for the next Thread it hasn't been
initialized, and so it contexts.get() returns null.
Simple fix : add the get method as follows :
public class SearchFactory {
private static ThreadLocal<WeakHashMap<Configuration, SearchFactory>>
contexts =
new ThreadLocal<WeakHashMap<Configuration, SearchFactory>>(){
@Override
public WeakHashMap<Configuration,SearchFactory> get() {
return new WeakHashMap<Configuration, SearchFactory>(2);
}
};
static {
Version.touch();
contexts.set( new WeakHashMap<Configuration, SearchFactory>(2) );
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira