• Bug
  • Status: Closed
  • Resolution: Fixed
  • drb
  • Reporter: sourceforgetracker
  • September 21, 2009
  • 0
  • Watchers: 0
  • September 22, 2009
  • September 22, 2009

Description

Hi.

The overriden method protected Class resolveClass(ObjectStreamClass clazz) throws ClassNotFoundException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); return Class.forName(clazz.getName(), false, classLoader); }

in the loadElementFromDiskElement method throws an Exception when the clazz is a primitive type (e.g. double). This happens when we put in the cache an object which contains such primitive types and the cache overflows to the disk. Also, why it was necessary to override the default behaviour of this method, since it already handles the primitive types as well?

Regards.

Sourceforge Ticket ID: 1517565 - Opened By: nobody - 5 Jul 2006 14:58 UTC

Comments

Sourceforge Tracker 2009-09-21

Logged In: YES user_id=693320

Hi

Following is a test where I try to reproduce the bug:

/**
 * Tests the loading of classes
 */
public void testClassloading() throws Exception {
    final DiskStore diskStore = createDiskStore();

    // Add a primitive
    long value = 123L;
    Element element = new Element("key", value);
    diskStore.put(element);
    Thread.sleep(1000);
    Element elementOut = diskStore.get("key");
    assertEquals(value, elementOut.getObjectValue());



    Primitive primitive = new Primitive();
    primitive.integerPrimitive = 123;
    primitive.longPrimitive = 456L;
    primitive.bytePrimitive = "a".getBytes()[0];
    primitive.charPrimitive = 'B';
    primitive.booleanPrimitive = false;

    //test Serializability
    ByteArrayOutputStream outstr = new ByteArrayOutputStream();
    ObjectOutputStream objstr = new ObjectOutputStream(outstr);
    objstr.writeObject(element);
    objstr.close();


    Element primitiveElement = new Element("primitive", primitive);
    diskStore.put(primitiveElement);
    Thread.sleep(1000);
    elementOut = diskStore.get("primitive");
    assertEquals(primitive, elementOut.getObjectValue());

}

public class Primitive implements Serializable { public int integerPrimitive; public long longPrimitive; public byte bytePrimitive; public char charPrimitive; public boolean booleanPrimitive;

/**
 * Indicates whether some other object is "equal to" this one.
 */
public boolean equals(Object object) {
    return object != null
            && object instanceof Primitive
            && ((Primitive) object).integerPrimitive == integerPrimitive
            && ((Primitive) object).longPrimitive == longPrimitive
            && ((Primitive) object).bytePrimitive == bytePrimitive
            && ((Primitive) object).charPrimitive == charPrimitive
            && ((Primitive) object).booleanPrimitive == booleanPrimitive;
} \}

The test passes with no issue. Can you please provide a test case for the bug you are experiencing.

As to why the change was made, it was because of a bug reported when ehcache is used with Tomcat. See http://sourceforge.net/tracker/index.php? func=detail&aid=1324221&group_id=93232&atid=603559

I have changed it to:

final ObjectInputStream objstr = new ObjectInputStream(instr) { protected Class resolveClass(ObjectStreamClass clazz) throws ClassNotFoundException, IOException { try { ClassLoader classLoader = Thread.currentThread ().getContextClassLoader(); return Class.forName(clazz.getName(), false, classLoader); } catch (ClassNotFoundException e) { return super.resolveClass(clazz); } } };

Hopefully that will work for you. I can see from the standard implementation that it resolves primitives but I am not sure how to reproduce your issue.

Greg Comment by: gregluck - 16 Jul 2006 07:18 UTC

Fiona OShea 2009-09-22

Re-opening so that I can properly close out these issues and have correct Resolution status in Jira