In looking at a CMP cache bug report, it is another instance of an
xdoclet generated key screwing up the hashCode implementation.
Here is the generated key:
/*
* Generated file - Do not edit!
*/
package com.lombardrisk.scratch;
import java.lang.*;
import java.util.Collection;
import java.util.Iterator;
import javax.ejb.CreateException;
import javax.ejb.EntityBean;
import com.lombardrisk.common.ServiceLocations;
import org.apache.log4j.Category;
/**
* Primary key for ScratchEntity.
* @ejb-pk
* @xdoclet-generated at 02-May-02 14:41:41
*/
public class ScratchEntityKey
extends java.lang.Object
implements java.io.Serializable
{
static final long serialVersionUID = 3511574961442126022L;
transient private int _hashCode = Integer.MIN_VALUE;
transient private String value = null;
public long id;
public ScratchEntityKey()
{
}
public ScratchEntityKey( long id )
{
this.id = id;
}
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
public int hashCode()
{
if( _hashCode == Integer.MIN_VALUE )
{
_hashCode += (int)this.id;
}
return _hashCode;
}
public boolean equals(Object obj)
{
if( !(obj instanceof com.lombardrisk.scratch.ScratchEntityKey) )
return false;
com.lombardrisk.scratch.ScratchEntityKey pk =
(com.lombardrisk.scratch.Scr
atchEntityKey)obj;
boolean eq = true;
if( obj == null )
{
eq = false;
}
else
{
eq = eq && this.id == pk.id;
}
return eq;
}
public String toString()
{
if( value == null )
{
value = "[.";
value += this.id+".";
value += "]";
}
return value;
}
}
The problem is the construct used to initialize and cache the hashCode
value.
Here is a trival program that demonstrates the problem:
import java.rmi.MarshalledObject;
import com.lombardrisk.scratch.ScratchEntityKey;
public class TstKey
{
public static void main(String[] args) throws Exception
{
ScratchEntityKey pk1 = new ScratchEntityKey(1);
System.out.println("Integer.MIN_VALUE="+Integer.MIN_VALUE);
System.out.println("pk1.hashCode="+pk1.hashCode());
MarshalledObject mo = new MarshalledObject(pk1);
ScratchEntityKey pk2 = (ScratchEntityKey) mo.get();
System.out.println("pk2.hashCode="+pk2.hashCode());
}
}
Which when runs, shows that the unserialized object pk2
has a hashCode of 0:
Integer.MIN_VALUE=-2147483648
pk1.hashCode=-2147483647
pk2.hashCode=0
So the unserialized pk1 value has a hashCode of 0 != -2147483647.
Its Serializable 101 stuff that default serialization does not
execute the default constructor and member intializations
during deserialization. Is xdoclet still generating this invalid
construct?
xxxxxxxxxxxxxxxxxxxxxxxx
Scott Stark
Chief Technology Officer
JBoss Group, LLC
xxxxxxxxxxxxxxxxxxxxxxxx
_______________________________________________________________
Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development