United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4968523 java.beans.Encoder.setPersistenceDelegate has static behavior
JDK-4968523 : java.beans.Encoder.setPersistenceDelegate has static behavior

Details
Type:
Bug
Submit Date:
2003-12-15
Status:
Closed
Updated Date:
2010-07-09
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
client-libs
OS:
solaris_2.6,generic
Sub-Component:
java.beans
CPU:
sparc,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.0,5.0,6
Fixed Versions:

Related Reports
Duplicate:
Duplicate:
Relates:
Relates:

Sub Tasks

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

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
                                     
2003-12-15
EVALUATION

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



Hardware and Software, Engineered to Work Together