Hi,

This patch adds a wrapper for null objects for JDWP. In order to distinguish between valid(object id 0) and invalid(null pointer) null values, the NullObject class has been created to represent a case where null is a valid value. This patch also update the reference VMIdManager to properly create NullObjectIds (object id 0) which hold references to NullObjects.

ChangeLog
2007-02-27  Kyle Galloway  <[EMAIL PROTECTED]>

   * gnu/classpath/jdwp/id/NullObjectId.java: New class.
   * gnu/classpath/jdwp/util/NullObject.java: New class.
* vm/reference/gnu/classpath/jdwp/VMIdManager.java (getObjectId): Handle null object.
   (get): Handle objectId of 0.
Index: vm/reference/gnu/classpath/jdwp/VMIdManager.java
===================================================================
RCS file: /sources/classpath/classpath/vm/reference/gnu/classpath/jdwp/VMIdManager.java,v
retrieving revision 1.7
diff -u -r1.7 VMIdManager.java
--- vm/reference/gnu/classpath/jdwp/VMIdManager.java	9 Mar 2006 23:18:29 -0000	1.7
+++ vm/reference/gnu/classpath/jdwp/VMIdManager.java	27 Feb 2007 21:26:53 -0000
@@ -337,6 +337,10 @@
    */
   public ObjectId getObjectId (Object theObject)
   {
+    // Special case: null
+    if (theObject == null)
+      return new NullObjectId ();
+    
     ReferenceKey ref = new ReferenceKey (theObject, _refQueue);
     ObjectId id = (ObjectId) _oidTable.get (ref);
     if (id == null)
@@ -364,6 +368,10 @@
   public ObjectId get (long id)
     throws InvalidObjectException
   {
+    // Special case: null
+    if (id == 0)
+      return new NullObjectId ();
+    
     ObjectId oid = (ObjectId) _idTable.get (new Long (id));
     if (oid == null)
       throw new InvalidObjectException (id);
Index: gnu/classpath/jdwp/id/NullObjectId.java
===================================================================
RCS file: gnu/classpath/jdwp/id/NullObjectId.java
diff -N gnu/classpath/jdwp/id/NullObjectId.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/classpath/jdwp/id/NullObjectId.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,42 @@
+package gnu.classpath.jdwp.id;
+
+import gnu.classpath.jdwp.exception.InvalidObjectException;
+import gnu.classpath.jdwp.util.NullObject;
+
+import java.lang.ref.SoftReference;
+
+/**
+ * This is a special case of an ObjectId.  When a varaible slot contains
+ * null as its value, this is a valid value despite the fact that it does
+ * not reference an object.  To represent this, this will always be the id
+ * of the NullObject (0).
+ *
+ * @author Kyle Galloway  <[EMAIL PROTECTED]>
+ */
+public class NullObjectId
+  extends ObjectId
+{
+  /**
+   * The object class that this id represents
+   */
+  public static final Class typeClass = NullObject.class;
+  
+  /**
+   * Constructs a new <code>NullObjectId</code>
+   */
+  public NullObjectId()
+  {
+    super();
+    setId((long) 0);
+    _reference = new SoftReference<NullObject>(new NullObject());
+    try
+      {
+        disableCollection();
+      }
+    catch(InvalidObjectException ex)
+      {
+        //This will not happen
+      }
+  }
+
+}
Index: gnu/classpath/jdwp/util/NullObject.java
===================================================================
RCS file: gnu/classpath/jdwp/util/NullObject.java
diff -N gnu/classpath/jdwp/util/NullObject.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/classpath/jdwp/util/NullObject.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,13 @@
+package gnu.classpath.jdwp.util;
+
+/**
+ * This is a placeholder for null.  There are several places in JDWP where null
+ * is a valid value (i.e. when geting the value of a variable slot that
+ * contains a null reference at that time).  This class distinguishes between
+ * these "meaningful" null values and invalid null pointers.
+ *
+ * @author Kyle Galloway  <[EMAIL PROTECTED]>
+ */
+public class NullObject
+{
+}

Reply via email to