JDK-4640519 : LTP: XMLEncoder does not write java.util.Set implementations correctly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-02-20
  • Updated: 2002-05-24
  • Resolved: 2002-05-24
Related Reports
Duplicate :  
Description

Name: gm110360			Date: 02/20/2002


FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

FULL OPERATING SYSTEM VERSION :
Win2k SP2

A DESCRIPTION OF THE PROBLEM :
XMLEncoder always encodes HashSets and TreeSets as empty
even if they are not empty.

ArrayLists and Vectors are encoded correctly.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. create new HashSet
2. add some elements
3. let the XMLEncoder encode

EXPECTED VERSUS ACTUAL BEHAVIOR :
I expectected:
Sets as well as Lists should be encoded including their
contents.

Reality:
XMLEncoder refuses to write Set contents, though it does
write List contents

This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.*;
import java.beans.*;

public class SetBug {

  public static void main(String[] args) throws Exception {

    List aList = new ArrayList();
    aList.add("foo");

    Set aSet = new HashSet();
    aSet.add("bar");

    XMLEncoder anEncoder = new XMLEncoder(System.out);
    anEncoder.writeObject(aSet);
    anEncoder.writeObject(aList);
    anEncoder.close();
  }
}

---------- END SOURCE ----------
(Review ID: 139836) 
======================================================================

Comments
EVALUATION This has been fixed as part of the fix to 4652928. A Collection persistence delegate was added so that classes like HashSet are now persistable. Fixed in 1.4.1 beta! ###@###.### 2002-05-24
24-05-2002