Bug 88581 - varargs treats "null" inputs wrong at the first position
Summary: varargs treats "null" inputs wrong at the first position
Status: RESOLVED DUPLICATE of bug 87042
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-19 19:55 EST by Eric Bodden CLA
Modified: 2005-03-21 10:10 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***