NPE when using IsolationLevel NONE, contains fix for the pro
lhotari Jun 14, 2004 4:05 AMI'm using JBossCache 1.01 with Hibernate. The IsolationLevel I'm using is NONE. I got this NPE:
2004-06-12 15:41:19,348 ERROR [UpHandler (GMS)] org.jboss.cache.TreeCache - getState(): failed lock
ing
tree
java.lang.NullPointerException
at org.jboss.cache.lock.IdentityLock.acquireReadLock(IdentityLock.java:175)
at org.jboss.cache.Node.acquireReadLock(Node.java:346)
at org.jboss.cache.Node.acquire(Node.java:331)
at org.jboss.cache.Node.acquireAll(Node.java:370)
at org.jboss.cache.TreeCache$MessageListenerAdaptor.getState(TreeCache.java:2438)
at org.jgroups.blocks.MessageDispatcher$ProtocolAdapter.passUp(MessageDispatcher.java:576)
at org.jgroups.blocks.RequestCorrelator.receive(RequestCorrelator.java:322)
at org.jgroups.blocks.MessageDispatcher$ProtocolAdapter.up(MessageDispatcher.java:638)
at org.jgroups.JChannel.up(JChannel.java:874)
at org.jgroups.stack.ProtocolStack.up(ProtocolStack.java:323)
at org.jgroups.stack.ProtocolStack.receiveUpEvent(ProtocolStack.java:339)
at org.jgroups.stack.Protocol.passUp(Protocol.java:489)
at org.jgroups.protocols.pbcast.STATE_TRANSFER.up(STATE_TRANSFER.java:102)
at org.jgroups.stack.Protocol.receiveUpEvent(Protocol.java:437)
at org.jgroups.stack.Protocol.passUp(Protocol.java:489)
at org.jgroups.protocols.pbcast.GMS.up(GMS.java:582)
at org.jgroups.stack.UpHandler.run(Protocol.java:60)
I had to add a class called LockStrategyNone. I guess this has been on the todo list since there was a comment "FIXME Ben" in the source code of LockStrategyFactory:
if (lockingLevel_ == null || lockingLevel_ == IsolationLevel.NONE) return null; // FIXME Ben !
I changed this to be:
if (lockingLevel_ == null || lockingLevel_ == IsolationLevel.NONE) return new LockStrategyNone();
source code for LockStrategyNone :
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.lock;
import EDU.oswego.cs.dl.util.concurrent.NullSync;
import EDU.oswego.cs.dl.util.concurrent.Sync;
/**
* Transaction isolation level of None.
*
* @author Lari Hotari
* @version $Revision$
*/
public class LockStrategyNone implements LockStrategy
{
private NullSync nullLock_;
public LockStrategyNone()
{
nullLock_ = new NullSync();
}
/**
* @see org.jboss.cache.LockStrategy#readLock()
*/
public Sync readLock()
{
return nullLock_;
}
/**
* @see org.jboss.cache.LockStrategy#upgradeLockAttempt(long)
*/
public Sync upgradeLockAttempt(long msecs)
{
return nullLock_;
}
/**
* @see org.jboss.cache.LockStrategy#writeLock()
*/
public Sync writeLock()
{
return nullLock_;
}
}edited LockStrategyFactory :
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.lock;
/**
* Factory to create LockStragtegy instance.
*
* @author Ben Wang
*/
public class LockStrategyFactory
{
private static LockStrategyFactory s_me = null;
/**
* Transaction locking isolation level. Default.
*/
private static IsolationLevel lockingLevel_ = IsolationLevel.REPEATABLE_READ;
/**
*
*/
protected LockStrategyFactory()
{
}
public static LockStrategyFactory getInstance()
{
if (s_me == null)
s_me = new LockStrategyFactory();
return s_me;
}
public LockStrategy getLockStrategy()
{
if (lockingLevel_ == null || lockingLevel_ == IsolationLevel.NONE)
return new LockStrategyNone();
if (lockingLevel_ == IsolationLevel.REPEATABLE_READ)
return new LockStrategyRepeatableRead();
if (lockingLevel_ == IsolationLevel.SERIALIZABLE)
return new LockStrategySerializable();
if (lockingLevel_ == IsolationLevel.READ_COMMITTED)
return new LockStrategyReadCommitted();
if (lockingLevel_ == IsolationLevel.READ_UNCOMMITTED)
return new LockStrategyReadUncommitted();
throw new RuntimeException("getLockStrategy: LockStrategy selection not recognized." +
" selection: " + lockingLevel_);
}
public static void setIsolationLevel(IsolationLevel level)
{
lockingLevel_ = level;
}
}