Bug 88581

Summary: varargs treats "null" inputs wrong at the first position
Product: [Eclipse Project] JDT Reporter: Eric Bodden <eric>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: major    
Priority: P3    
Version: 3.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Eric Bodden CLA 2005-03-19 19:55:39 EST
Hi. When passing "null" into a varargs method foo(Object... o) at the *first* 
position such as foo(null,oneObject,anotherObject), what you retrieve inside the 
method foo is not an array with array[0]==null, array[1]==oneObject and array[2]
==anotherObject, but simply "null" as the full array value.

When I pass in foo(new Object[]{null,oneObject,anotherObject}) it works just 
fine. Also there is apparently no problem, when null occurs at any other 
position but the first, such as foo(oneObject,null,anotherObject).
Comment 1 Olivier Thomann CLA 2005-03-20 09:01:30 EST
Could you please provide the build id?
Comment 2 Eric Bodden CLA 2005-03-20 09:16:15 EST
This is I20050219-1500.

Here my test case:

____

public class T {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		foo("abc",null);
		foo(new Object[]{null,"abc"});
		foo(null,"abc");

	}
	
	static void foo(Object... o) {
		System.out.println(o[1]);
	}

}

____
This outputs:

null
abc
Exception in thread "main" java.lang.NullPointerException
	at T.foo(T.java:16)
	at T.main(T.java:11)

(because o is null in the third case)
Comment 3 Olivier Thomann CLA 2005-03-20 21:08:41 EST
With latest, I get:
null
abc
abc

Closing as WORKSFORME.
Comment 4 Olivier Thomann CLA 2005-03-21 10:10:00 EST
Reopen to close as duplicate.
Comment 5 Olivier Thomann CLA 2005-03-21 10:10:10 EST

*** This bug has been marked as a duplicate of 87042 ***