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.
======================================================================
- relates to
-
JDK-4239039 (ref) (spec) Reference-object constructors allow null queues
-
- Closed
-