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

(ref) WeakReference 2-parameter constructor fails to throw NullPointerException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs
    • generic
    • generic



      Name: dk106046 Date: 03/12/2004

      FULL JDK VERSION(S) :
      Both 1.4.2 and 1.5.0

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

      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b37)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b37, mixed mode)

      DESCRIPTION -
       From the API docs, 2-parameter constructor of WeakReference should throw NullPointerException when
      the ReferenceQueue argument is NULL. But it does not do so. This is true for all subclasses of
      Reference class, i.e., PhantomReference, SoftReference and WeakReference.

      To recreate the problem, please use the testcase below :

      import java.lang.ref.*;
      import java.util.*;
      import java.io.*;

      public class WeakRefTest {

         public static void main(String[] args) {
             Object obj = new Object();

             try {
                 WeakReference wr = new WeakReference(obj, null);
                 System.out.println("Error: Failed to return NullPointerException");
                 System.out.println("TEST FAILED");
             } catch (NullPointerException e) {
                 System.out.println("TEST PASSED");
             }
         }
      }

      Compile and run this testcase as java WeakRefTest
      It passes if NullPointerException is thrown. But we see that no exception is thrown, and hence the test fails.

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

            mr Mark Reinhold
            dkorbel David Korbel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: