|
Quick Lists
|
|
Bug ID:
|
4818598
|
|
Votes
|
1
|
|
Synopsis
|
LTP: XMLEncoder doesn't save state for Class properties with default values
|
|
Category
|
java:classes_beans
|
|
Reported Against
|
1.4
, 2.0
|
|
Release Fixed
|
7(b20)
|
|
State
|
10-Fix Delivered,
bug
|
|
Priority:
|
4-Low
|
|
Related Bugs
|
4818600
|
|
Submit Date
|
14-FEB-2003
|
|
Description
|
Bean properties of type Class are not persisted by the XMLEncoder if they have been assigned a default value by the bean. To reproduce, use the following bean classes:
public class Bean1
{
public Class getClassProperty()
{
return classProperty;
}
public void setClassProperty(Class value)
{
classProperty=value;
}
private String stringProperty;
private Class classProperty=Object.class; // <-- here is problem
}
public class Bean2
{
public Class getClassProperty()
{
return classProperty;
}
public void setClassProperty(Class value)
{
classProperty=value;
}
private String stringProperty;
private Class classProperty;
}
Before encoding each bean, change the value of the bean's classProperty to e.g. java.lang.Integer. After encoding, the value of this property will not be represented in the XML output for Bean1.
Bean1:
{classProperty=class java.lang.Integer}
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.1" class="java.beans.XMLDecoder">
< customer class="com.sun.jato.tools.sunone._temp.Bean1"/>
</java>
Bean2:
{classProperty=class java.lang.Integer}
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.1" class="java.beans.XMLDecoder">
< customer class="com.sun.jato.tools.sunone._temp.Bean2">
<void property="classProperty">
<class>java.lang.Integer</class>
</void>
</ customer >
</java>
xxxxx@xxxxx 2003- customer -13
|
|
Work Around
|
The only workaround currently known is to not use Class properties with default values.
xxxxx@xxxxx 2003-02-13
|
|
Evaluation
|
Can't see anything obvious. This will not be fixed for mantis so I'm lowering the priority. This issue only affects properties which have a Class type that has a default value.
xxxxx@xxxxx 2003-02-19
The following evaluation has been adapted from a dialog with the original author.
The bug is in the Class.class PersistenceDelegate (PD) which has a broken mutatesTo() method.
Classes aren't mutable like other beans.
The fix is to include the following override in MetaData.java.
class java_lang_Class_PersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance == newInstance;
}
protected Expression instantiate(Object oldInstance, Encoder out) {
<... as before ...>
}
If the guy needs a fix now it should be possible to submit the PD
for Class.class to the encoder in the normal way. We should make the
methods of PD all public so that you can use the decorator pattern
instead of having to the copy the code out of MetaData.java in
cases like this.
Continuing....
Looking through the MetaData.java file - at the
other delegates which are direct subclasses of PerististenceDelegate
I couldn't see why they wouldn't suffer the same problem as the
one you just brought up for the PD of Class.class. I've just tried
it and, sure enough Fields, at least, suffer the same problem as classes.
So the choices seem to be to add mutatesTo() methods to all (or at least
many) of the direct subclasses of PersistenceDelegate - or to change the
implementation of mutatesTo() in the PersistenceDelegate class itself
so that it doesn't need to be overridden all the time. I've tested
the second option and it seems to work - though it was on just one small
example.
The one wrinkle I found is that the DefaultPersisenceDelegate calls
super.mutatesTo() and that needs to use the definition of the
superclass as is - so the current implementation needs moving into
DPD before dumping it - if you see what I mean.
This may, of course, cause other problems so it would need to be
thoroughly tested against your golden files - but looking at
everything now it seems to me that this might have a number of
benefits to the rest of the codebase. In particular, the PD's for
List, Map and so on, all use a weird construction involving
MetaData.equals() method when trying to line up properties - it
might turn out that if the mutatesTo() method was fixed that
this wouldn't be necessary.
xxxxx@xxxxx 2003-02-24
We should override the mutatesTo() method in the following classes:
java_lang_reflect_Field_PersistenceDelegate
java_lang_reflect_Method_PersistenceDelegate
java_awt_MenuShortcut_PersistenceDelegate
javax_swing_Box_PersistenceDelegate
Posted Date : 2007-08-07 12:51:07.0
|
|
Comments
|
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |