JDK-4968523 : java.beans.Encoder.setPersistenceDelegate has static behavior
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.4.0,5.0,6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris_2.6
  • CPU: generic,sparc
  • Submitted: 2003-12-15
  • Updated: 2010-07-09
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b10Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
Name: dsR10051			Date: 12/15/2003


Filed By      : SPB JCK team (###@###.###)
JDK           : java full version "1.5.0-beta-b30"
JCK           : 1.5
Platform[s]   : Solaris
switch/Mode   : 
JCK test owner : http://javaweb.eng/jct/sqe/JCK-tck/usr/owners.jto
Failing Test [s] : N/A


Specification excerpt:
======================
--------- J2SE API spec v.1.5 ---------
 * @(#)Encoder.java     1.17 03/09/18
... 

    /**
     * Sets the persistence delegate associated with this <code>type</code> to
     * <code>persistenceDelegate</code>.
     *
     * @param  type The class of objects that <code>persistenceDelegate</code> applies to.
     * @param  persistenceDelegate The persistence delegate for instances of <code>type</code>.
     *
     * @see #getPersistenceDelegate
     * @see java.beans.Introspector#getBeanInfo
     * @see java.beans.BeanInfo#getBeanDescriptor
     */
    public void setPersistenceDelegate(Class type, PersistenceDelegate persistenceDelegate) {

...
---------- end-of-excerpt ---------------

Problem description
===================
Javadoc for method of class java.beans.Encoder
public void setPersistenceDelegate(Class type, PersistenceDelegate persistenceDelegate)
says nothing about static nature for method behavior.
If developer sets persistence delegate for one Encoder, this persistent delegate
is used for another encoder instances  to express the  state of an instance of a given
type. It should be documented.

Minimized test  demonstrates this bug.
    
Minimized test:
===============
------- Test01.java -------
import java.io.ByteArrayOutputStream;
import java.beans.*;

public class Test01 {

    public static void main(String[] args) {

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        XMLEncoder xml = new XMLEncoder(out);
        MyDelegate delegate = new MyDelegate("statement");
        xml.setPersistenceDelegate(MyBean2.class, delegate);

        ByteArrayOutputStream out_new = new ByteArrayOutputStream();
        XMLEncoder xml_new = new XMLEncoder(out_new);

        if (delegate == xml.getPersistenceDelegate(MyBean2.class)) {
            System.out.println("Failed: XMLEncoder has persistence delegate that has been set " +
                "for another XMLEncoder");
        } else {
            System.out.println("OKAY");
        }
    }
}

class MyDelegate extends PersistenceDelegate {

    public MyDelegate(String statement) {
    }

    protected Expression instantiate(Object obj, Encoder encoder) {
        return null;
    }

    protected void initialize(Class type, Object oldInstance, Object newInstance, Encoder out) {
    }

}
MyBean2 
public class MyBean2 {
    private String s;
    public MyBean2(String s) {
        setString(s);
    }
    public void setString(String s) {
        this.s = s;
    }
    public String getString() {
        return s;
    }
}

------- end-of-Test01.java -------

Minimized test output:
======================
/set/java/jdk1.5.0/solaris/bin/java Test01
Failed: XMLEncoder has persistence delegate that has been set for another XMLEncoder

JCK test source location:
==========================
/java/re/jck/1.5/promoted/latest/JCK-runtime-15/tests
    
======================================================================

Comments
EVALUATION It is necessary to remove static behavior.
02-02-2007

EVALUATION public void setPersistenceDelegate(Class type, PersistenceDelegate persistenceDelegate) says nothing about static nature for method behavior. ###@###.### 2003-12-15 We should consider adding this words or making the method static. ###@###.### 2005-04-20 14:33:23 GMT
15-12-2003