Author: sshafroi
Date: 2008-07-25 14:14:35 +0200 (Fri, 25 Jul 2008)
New Revision: 6754

Modified:
   
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractReflectionVisitor.java
Log:
Issue SKER4943:  (IllegalAccessException "(Failed to visit object 
OrClauseImpl[(1 OR 2)])")

We do not need to set the setAccessible back to false for each call, since we 
are the only one that uses the method. And this will fix the error.

I also made the locking a bit better, so the normal operations will work 
without locking. Locking is only done when then unlocked version fails.


Modified: 
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractReflectionVisitor.java
===================================================================
--- 
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractReflectionVisitor.java
   2008-07-24 20:44:51 UTC (rev 6753)
+++ 
trunk/query-api/src/main/java/no/sesat/search/query/parser/AbstractReflectionVisitor.java
   2008-07-25 12:14:35 UTC (rev 6754)
@@ -90,26 +90,30 @@
     private static WeakHashMap<Class<? extends Visitor>, 
ConcurrentHashMap<Class<? extends Clause>, Method>> cache =
         new WeakHashMap<Class<? extends Visitor>, ConcurrentHashMap<Class<? 
extends Clause>, Method>>();
     private static ReadWriteLock cacheLock = new ReentrantReadWriteLock();
-    private static Lock cacheReadLock = cacheLock.readLock();
     public void visit(final Clause clause) {
-        cacheReadLock.lock();
         ConcurrentHashMap<Class<? extends Clause>, Method> map = 
cache.get(getClass());
-        cacheReadLock.unlock();
         if (map == null) {
-            map = new ConcurrentHashMap<Class<? extends Clause>, Method>();
-            cacheLock.writeLock().lock();
-            cache.put(getClass(), map);
-            cacheLock.writeLock().unlock();
+            try{
+                cacheLock.writeLock().lock();
+                map = cache.get(getClass());
+                if (map == null) {
+                    map = new ConcurrentHashMap<Class<? extends Clause>, 
Method>();
+                    cache.put(getClass(), map);
+                }
+            }
+            finally {
+                cacheLock.writeLock().unlock();
+            }
         }
+
         Method method = map.get(clause.getClass());
         if (method == null) {
             method = getMethod(clause.getClass());
+            method.setAccessible(true);
             map.put(clause.getClass(), method);
         }
         assert method.equals(getMethod(clause.getClass()));
-
         try {
-            method.setAccessible(true);
             method.invoke(this, new Object[] {clause});
 
         } catch (IllegalArgumentException ex) {
@@ -127,9 +131,6 @@
 
         } catch (IllegalAccessException ex) {
             LOG.error(ERR_FAILED_TO_VISIT + clause, ex);
-
-        }  finally  {
-            method.setAccessible(false);
         }
     }
 

_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits

Reply via email to