Name: gm110360 Date: 03/22/2004
FULL PRODUCT VERSION :
java version "1.5.0-beta" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c) Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
SunOS zwols085 5.8 Generic_108528-22 sun4u sparc SUNW,UltraAX-i2
A DESCRIPTION OF THE PROBLEM :
Calling a varargs method with a single null (as opposed to a single object that has a value of null), causes the value of the parameter to be null, rather than an array containing a single null element.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a method with variable arguments.
Call this method with a single null parameter.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The variable argument parameter should be an array of length 1 with a single null value.
ACTUAL -
The variable argument parameter is set to null itself. This causes problems if the method tries to iterate on this argument immediately - a NullPointerException results. This is inconsistent, particularly considering that a variable containing a value of null is treated properly.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
static void test(Object... value) {
if (value == null) {
System.out.println("null value!");
} else {
System.out.println("OK");
}
}
public static void main(String[] args) {
Object n = null;
System.out.print("Object with a value of null. ");
test(n);
System.out.print("No values at all.");
test();
System.out.print("A single null.");
test(null);
System.out.print("Two null's. ");
test(null, null);
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Test for null in all methods that require variable arguments, or assign null arguments to a value before passing to varargs methods.
(Incident Review ID: 244433)
======================================================================
- duplicates
-
JDK-5024518 need warning if varargs argument isn't boxed
- Resolved