History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: CACHE-73
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Martin Heitz
Votes: 3
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
OSCache

NullpointerException after deserialization of AbstractConcurrentReadCache

Created: 27/Jan/04 06:11 AM   Updated: 23/Jan/05 04:59 PM
Component/s: Base Classes
Affects Version/s: 2.0.1, 2.0.2
Fix Version/s: 2.1

Environment:
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)


 Description  « Hide
In the deserialization of AbstractConcurrentReadCache the "table" variable seems to remain null (although the code looks fine at first glance in readObject()).

(This problem seems to exist already in Version 1.7.5, where I also received a NPex after deserialization.)

Reproduceability with the following simple JUnit test
/**
* tests the serialization and deserialization of OSCache
*
* @throws IOException if test fails
* @throws ClassNotFoundException if test fails
*/
public void testCacheSerialization()
throws IOException, ClassNotFoundException, NeedsRefreshException
{
final Cache written = new Cache(true, false);
written.putInCache("key", "before");
assertEquals("failed to put in cache before serialization", "before", written.getFromCache("key"));

final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(written);

final byte[] serialized = baos.toByteArray();
baos.close();

final ByteArrayInputStream bais = new ByteArrayInputStream(serialized);
final ObjectInputStream ois = new ObjectInputStream(bais);
final Cache read = (Cache) ois.readObject();
ois.close();

read.getFromCache("key");
}
...
causes
...
java.lang.NullPointerException
at com.opensymphony.oscache.base.algorithm.AbstractConcurrentReadCache.get(AbstractConcurrentReadCache.java:686)
at com.opensymphony.oscache.base.Cache.getCacheEntry(Cache.java:594)
at com.opensymphony.oscache.base.Cache.getFromCache(Cache.java:227)
at com.opensymphony.oscache.base.Cache.getFromCache(Cache.java:180)
at com.claritycontrol.ars.CacheTestCase.testCacheSerialization(CacheTestCase.java:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)

Best regards from snowy Black Forest, Germany,
   Mattin


 All   Comments   Change History      Sort Order:
Pieter Coucke - [31/Jan/04 05:10 AM ]
According to http://java.sun.com/j2se/1.4.2/docs/api/java/io/ObjectInputStream.html the readObject and writeObject methods should be private instead of protected. At least I get another error now when I run the testcase.

Pieter Coucke - [31/Jan/04 05:21 AM ]
I solved the testcase with the following.

this.barrierLock = new Object();

should be added to

public AbstractConcurrentReadCache(int initialCapacity, float loadFactor)

and to

private synchronized void readObject(java.io.ObjectInputStream s)


This can only be done when barrierLock is not defined as "final" anymore:

protected transient Object barrierLock;



If you want to keep the final property of barrierLock, replace Object with a Serializable class and remove the transient modifier.

Chris Miller - [09/Jul/04 10:18 AM ]
Switched over to using a Boolean for the barrierLock since it's serializable. It is possible there are still other outstanding deserialization issues - if so please let me know and I'll reopen this bug.

Only the AbstractCacheAdministrator class was affected by this fix.