Author: sshafroi
Date: 2008-07-22 14:01:11 +0200 (Tue, 22 Jul 2008)
New Revision: 6749
Modified:
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractClause.java
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractLeafClause.java
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractOperationClause.java
trunk/query-api/src/main/java/no/sesat/search/query/parser/XorClauseImpl.java
Log:
SEARC-2837 - NPE in AbstractAlternation.leftChild
Only synchronize on the specific hash, and only when a clause needs to be
created. If another thread have created a thread in the meantime then this
clause will be returned by the addClauseInUse method.
Modified:
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractClause.java
===================================================================
---
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractClause.java
2008-07-21 14:55:07 UTC (rev 6748)
+++
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractClause.java
2008-07-22 12:01:11 UTC (rev 6749)
@@ -95,13 +95,23 @@
* for the Clause we are about to add to the mappings.
* @param clause the Clause we are about to add to the mappings.
* @param weakCache the map containing the key to WeakReference (of the
Clause) mappings.
+ * @return If the weakCache contained an clause for the key, then this is
returned. Otherwise
+ * the clasue entered as a parameter is returned.
*/
- protected static final <T extends AbstractClause> void addClauseInUse(
+ protected static final <T extends AbstractClause> T addClauseInUse(
final String key,
final T clause,
final ReferenceMap<String,T> weakCache) {
-
- weakCache.put(key, clause);
+ synchronized(weakCache) {
+ T tmp = weakCache.get(key);
+ if(tmp == null) {
+ weakCache.put(key, clause);
+ return clause;
+ }
+ else {
+ return tmp;
+ }
+ }
}
/**
Modified:
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractLeafClause.java
===================================================================
---
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractLeafClause.java
2008-07-21 14:55:07 UTC (rev 6748)
+++
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractLeafClause.java
2008-07-22 12:01:11 UTC (rev 6749)
@@ -61,7 +61,7 @@
* @return Either a clause already in use that matches this term and field,
* or a newly created cluase for this term and field.
*/
- public synchronized static <T extends AbstractLeafClause> T createClause(
+ public static <T extends AbstractLeafClause> T createClause(
final Class<T> clauseClass,
final String term,
final String field,
@@ -114,7 +114,7 @@
}
if(healthy){
- addClauseInUse(key, clause, weakCache);
+ return addClauseInUse(key, clause, weakCache);
}
}finally{
engine.setState(null);
Modified:
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractOperationClause.java
===================================================================
---
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractOperationClause.java
2008-07-21 14:55:07 UTC (rev 6748)
+++
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractOperationClause.java
2008-07-22 12:01:11 UTC (rev 6749)
@@ -62,7 +62,7 @@
* @param weakCache the map containing the key to WeakReference (of the
Clause) mappings.
* @return Either a clause already in use that matches this term and
field, or a newly created cluase for this term and field.
*/
- public static synchronized <T extends AbstractOperationClause> T
createClause(
+ public static <T extends AbstractOperationClause> T createClause(
final Class<T> clauseClass,
final String term,
final Clause left,
@@ -112,7 +112,7 @@
}
if( healthy ){
- addClauseInUse(key, clause, weakCache);
+ return addClauseInUse(key, clause, weakCache);
}
}
Modified:
trunk/query-api/src/main/java/no/sesat/search/query/parser/XorClauseImpl.java
===================================================================
---
trunk/query-api/src/main/java/no/sesat/search/query/parser/XorClauseImpl.java
2008-07-21 14:55:07 UTC (rev 6748)
+++
trunk/query-api/src/main/java/no/sesat/search/query/parser/XorClauseImpl.java
2008-07-22 12:01:11 UTC (rev 6749)
@@ -1,5 +1,5 @@
/*
- * Copyright (2005-2007) Schibsted Søk AS
+ * Copyright (2005-2008) Schibsted Søk AS
* This file is part of SESAT.
*
* SESAT is free software: you can redistribute it and/or modify
@@ -140,7 +140,7 @@
);
if( healthy ){
- addClauseInUse(term, clause, weakCache);
+ return addClauseInUse(term, clause, weakCache);
}
}
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits