Author: ssmiweve Date: 2008-11-30 19:38:28 +0100 (Sun, 30 Nov 2008) New Revision: 7003
Modified: branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/AbstractClause.java Log: SEARCH-2837 NPE in AbstractAlternation.leftChild alternative solution with no static synchronisation Modified: branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/AbstractClause.java =================================================================== --- branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/AbstractClause.java 2008-11-28 22:54:37 UTC (rev 7002) +++ branches/2.18/query-api/src/main/java/no/sesat/search/query/parser/AbstractClause.java 2008-11-30 18:38:28 UTC (rev 7003) @@ -102,16 +102,26 @@ final String key, final T clause, final ReferenceMap<String,T> weakCache) { - synchronized(weakCache) { - T tmp = weakCache.get(key); - if(tmp == null) { - weakCache.put(key, clause); - return clause; + + T inUse = weakCache.get(key); + + if(null == inUse){ + // clause is not in use + inUse = weakCache.put(key, clause); + + if(null != inUse){ + // weakCache.get(key) is only read volatile so it may be there was another clause already there + // and only the write volatile inside weakCache.put(key.calue) sees through this small window. + + // restore original clause that was in use + weakCache.put(key, inUse); + + }else{ + inUse = clause; } - else { - return tmp; - } } + + return inUse; } /** @@ -180,18 +190,13 @@ return success; } - /** You must use <CODE>AbstractClause(String, Set<Predicate>, Set<Predicate>)</CODE> instead. - * This constructor will throw an IllegalArgumentException. - **/ -// protected AbstractClause() { -// throw new IllegalArgumentException(ERR_MUST_ALWAYS_USE_ARGED_CONSTRUCTOR); -// } /** We need a no-argument constructor for serialization. */ protected AbstractClause() { this.term = null; this.knownPredicates = null; this.possiblePredicates = null; } + /** * Create clause with the given term, known and possible predicates. * @param term the term (query string) for this clause. @@ -236,17 +241,28 @@ } - /** [EMAIL PROTECTED] - */ public void accept(final Visitor visitor) { visitor.visit(this); } - /** [EMAIL PROTECTED] - */ @Override public String toString() { return getClass().getSimpleName() + '[' + getTerm() + ']'; } + /** Provide a replicatable hashCode so the same segment inside the ConcurrentHashMap + * is used for any accidently duplicate created clauses. + * The ConcurrentHashMap is used in this package's implementation of the flyweight pattern. + * + * It is intended for equals(..) to use instance reference equality, ie Object.equals(..). + * + * [EMAIL PROTECTED] + * @return [EMAIL PROTECTED] + */ + @Override + public int hashCode() { + + return ((getClass().hashCode() * 37) + term.hashCode()) + 17; + } + } _______________________________________________ Kernel-commits mailing list Kernel-commits@sesat.no http://sesat.no/mailman/listinfo/kernel-commits