Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 14662 invoked from network); 19 Dec 2007 10:50:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Dec 2007 10:50:42 -0000 Received: (qmail 51995 invoked by uid 500); 19 Dec 2007 10:50:31 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 51957 invoked by uid 500); 19 Dec 2007 10:50:31 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 51941 invoked by uid 99); 19 Dec 2007 10:50:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Dec 2007 02:50:31 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Dec 2007 10:50:17 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id BBB731A9838; Wed, 19 Dec 2007 02:50:20 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r605510 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state: ItemStateCache.java ItemStateReferenceCache.java LocalItemStateManager.java MLRUItemStateCache.java Date: Wed, 19 Dec 2007 10:50:16 -0000 To: commits@jackrabbit.apache.org From: mreutegg@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071219105020.BBB731A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mreutegg Date: Wed Dec 19 02:50:15 2007 New Revision: 605510 URL: http://svn.apache.org/viewvc?rev=605510&view=rev Log: JCR-1271: NullPointerException when iterating over properties Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java?rev=605510&r1=605509&r2=605510&view=diff ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateCache.java Wed Dec 19 02:50:15 2007 @@ -18,9 +18,6 @@ import org.apache.jackrabbit.core.ItemId; -import java.util.Set; -import java.util.Collection; - /** * An ItemStateCache maintains a cache of ItemState * instances. @@ -50,6 +47,13 @@ ItemState retrieve(ItemId id); /** + * Returns all the cached item states. + * + * @return newly allocated item state array + */ + ItemState[] retrieveAll(); + + /** * Stores the specified ItemState object in the map * using its ItemId as the key. * @@ -77,29 +81,6 @@ * @return true if this cache contains no entries. */ boolean isEmpty(); - - /** - * Returns the number of entries in this cache. - * - * @return number of entries in this cache. - */ - int size(); - - /** - * Returns an unmodifiable set view of the keys (i.e. ItemId - * objects) of the cached entries. - * - * @return a set view of the keys of the cached entries. - */ - Set keySet(); - - /** - * Returns an unmodifiable collection view of the values (i.e. - * ItemState objects) contained in this cache. - * - * @return a collection view of the values contained in this cache. - */ - Collection values(); /** * Informs the cache that the item was modified and the cache might need to Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java?rev=605510&r1=605509&r2=605510&view=diff ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateReferenceCache.java Wed Dec 19 02:50:15 2007 @@ -21,9 +21,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Set; -import java.util.Collections; -import java.util.Collection; import java.io.PrintStream; /** @@ -42,6 +39,7 @@ * collector if they are thus rendered weakly reachable. * * + * This implementation of ItemStateCache is thread-safe. */ public class ItemStateReferenceCache implements ItemStateCache, Dumpable { @@ -86,7 +84,7 @@ /** * {@inheritDoc} */ - public boolean isCached(ItemId id) { + public synchronized boolean isCached(ItemId id) { // check primary cache return refs.contains(id); } @@ -94,7 +92,7 @@ /** * {@inheritDoc} */ - public ItemState retrieve(ItemId id) { + public synchronized ItemState retrieve(ItemId id) { // fake call to update stats of secondary cache cache.retrieve(id); @@ -105,7 +103,15 @@ /** * {@inheritDoc} */ - public void cache(ItemState state) { + public synchronized ItemState[] retrieveAll() { + // values of primary cache + return (ItemState[]) refs.values().toArray(new ItemState[refs.size()]); + } + + /** + * {@inheritDoc} + */ + public synchronized void cache(ItemState state) { ItemId id = state.getId(); if (refs.contains(id)) { log.warn("overwriting cached entry " + id); @@ -120,7 +126,7 @@ /** * {@inheritDoc} */ - public void evict(ItemId id) { + public synchronized void evict(ItemId id) { // fake call to update stats of secondary cache cache.evict(id); // remove from primary cache @@ -130,14 +136,14 @@ /** * {@inheritDoc} */ - public void dispose() { + public synchronized void dispose() { cache.dispose(); } /** * {@inheritDoc} */ - public void evictAll() { + public synchronized void evictAll() { // fake call to update stats of secondary cache cache.evictAll(); // remove all weak references from primary cache @@ -147,7 +153,7 @@ /** * {@inheritDoc} */ - public void update(ItemId id) { + public synchronized void update(ItemId id) { // delegate cache.update(id); } @@ -155,40 +161,16 @@ /** * {@inheritDoc} */ - public boolean isEmpty() { + public synchronized boolean isEmpty() { // check primary cache return refs.isEmpty(); } - /** - * {@inheritDoc} - */ - public int size() { - // size of primary cache - return refs.size(); - } - - /** - * {@inheritDoc} - */ - public Set keySet() { - // keys of primary cache - return Collections.unmodifiableSet(refs.keySet()); - } - - /** - * {@inheritDoc} - */ - public Collection values() { - // values of primary cache - return Collections.unmodifiableCollection(refs.values()); - } - //-------------------------------------------------------------< Dumpable > /** * {@inheritDoc} */ - public void dump(PrintStream ps) { + public synchronized void dump(PrintStream ps) { ps.println("ItemStateReferenceCache (" + this + ")"); ps.println(); ps.print("[refs] "); Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java?rev=605510&r1=605509&r2=605510&view=diff ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java Wed Dec 19 02:50:15 2007 @@ -35,7 +35,7 @@ * cache of weak references to ItemState objects issued by this * ItemStateManager */ - private final ItemStateReferenceCache cache; + private final ItemStateCache cache; /** * Shared item state manager @@ -140,7 +140,7 @@ } // check cache. synchronized to ensure an entry is not created twice. - synchronized (cache) { + synchronized (this) { state = cache.retrieve(id); if (state == null) { // regular behaviour @@ -333,13 +333,9 @@ // this LocalItemStateManager instance is no longer needed; // cached item states can now be safely discarded - - // JCR-798: copy cached item states to array - // to avoid ConcurrentModificationException - ItemState[] isa = (ItemState[]) cache.values().toArray( - new ItemState[cache.size()]); - for (int i = 0; i < isa.length; i++) { - ItemState state = isa[i]; + ItemState[] states = cache.retrieveAll(); + for (int i = 0; i < states.length; i++) { + ItemState state = states[i]; if (state != null) { dispatcher.notifyStateDiscarded(state); // let the item state know that it has been disposed Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java?rev=605510&r1=605509&r2=605510&view=diff ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/MLRUItemStateCache.java Wed Dec 19 02:50:15 2007 @@ -16,17 +16,13 @@ */ package org.apache.jackrabbit.core.state; +import java.util.Iterator; + import org.apache.commons.collections.map.LinkedMap; import org.apache.jackrabbit.core.ItemId; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Set; -import java.util.Collections; -import java.util.Collection; -import java.util.ArrayList; -import java.util.Iterator; - /** * An ItemStateCache implementation that internally uses a * {@link LinkedMap} to maintain a cache of ItemState objects. The @@ -112,6 +108,15 @@ /** * {@inheritDoc} */ + public ItemState[] retrieveAll() { + synchronized (cache) { + return (ItemState[]) cache.values().toArray(new ItemState[cache.size()]); + } + } + + /** + * {@inheritDoc} + */ public void update(ItemId id) { touch(); synchronized (cache) { @@ -185,39 +190,6 @@ public boolean isEmpty() { synchronized (cache) { return cache.isEmpty(); - } - } - - /** - * {@inheritDoc} - */ - public int size() { - synchronized (cache) { - return cache.size(); - } - } - - /** - * {@inheritDoc} - */ - public Set keySet() { - synchronized (cache) { - return Collections.unmodifiableSet(cache.keySet()); - } - } - - /** - * {@inheritDoc} - */ - public Collection values() { - synchronized (cache) { - ArrayList list = new ArrayList(cache.size()); - Iterator iter = cache.values().iterator(); - while (iter.hasNext()) { - Entry entry = (Entry) iter.next(); - list.add(entry.state); - } - return list; } }