• Bug
  • Status: Open
  • 2 Major
  • Resolution:
  • DSO:L1
  • prodmgmt
  • Reporter: hhuynh
  • September 17, 2008
  • 0
  • Watchers: 0
  • March 19, 2010

Attachments

Description

According to Sun’s spec http://java.sun.com/javase/6/docs/api/java/util/Set.html#toArray(T[])
array with bigger size than the collection in call toArray(T[] a) will be null terminated.

We are not following that spec. The output does show the array in local VM is null terminated but the (third) value on the server isn’t null (see screen shot)

public class Test { // Roots private Map<String, String> map = new ConcurrentHashMap<String, String>(); private Object[] array = new Object[4];

public void run() \{
	map.put("key1", "value1");
	map.put("key2", "value2");

	synchronized (array) \{
		Arrays.fill(array, "filler");
		System.out.println("before: " + Arrays.asList(array));
		array = map.entrySet().toArray(array);
		System.out.println("after: " + Arrays.asList(array));
	\}
\}

public static void main(String[] args) \{
	new Test().run();
\} \}

================================================================================================= Output:

before: [filler, filler, filler, filler] after: [key1=value1, key2=value2, null, filler]

Comments

Hung Huynh 2008-09-17

see system test GenericMapTest.testEntrySetToArray2()