Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4247236

(ref) Weak reference created with null referent cannot be enqueued

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b32
    • CPU:
      generic, sparc
    • OS:
      generic, solaris_2.5.1
    • Verification:
      Verified

      Description



      Name: akC45999 Date: 06/17/99



      The Java 2 Standard Edition API Specification (jdk1.3H) reads:
      ...
      public boolean enqueue()

          Adds this reference object to the queue with which it
          is registered, if any.
          Returns:
             true if this reference object was successfully
             enqueued; false if it was already enqueued or if it
             was not registered with a queue when it was created
      ...

      But the following test shows that if we create WeakReference with null
      referent object, like this - WeakReference(null, queue), it could not be
      enqueued - enqueue() returns false.

      The same concerns SoftReference and PhantomReference.

       Test code:
       
        novo51% java -version
        java version "1.3"
        Classic VM (build JDK-1.3-H, green threads, sunwjit)
        novo51% javac test.java
        novo51% java test
        Failed.
        novo51%
       
       ----------------------- test.java ------------------------------------
        import java.io.PrintStream;
        import java.lang.ref.*;
       
        public class test {
       
            public static void main (String args[]) {
                 ReferenceQueue queue = new ReferenceQueue();
                 WeakReference refWeak = new WeakReference(null, queue);
                 if (refWeak.enqueue() == false) {
                     System.out.println("Failed.");
                     return;
                 }
                 System.out.println("Passed.");
            }
        }
       -----------------------------------------------------------------------

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            mr Mark Reinhold
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: