-
Bug
-
Resolution: Fixed
-
P3
-
7
-
b17
-
x86
-
windows_xp, windows_vista
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2216481 | 7u4 | Sergey Malenkov | P3 | Closed | Fixed | b02 |
FULL PRODUCT VERSION :
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Confirmed under Windows Vista and 7 32bit, XP and 64bit untested
A DESCRIPTION OF THE PROBLEM :
XMLEncoder fails to encode a bean when it extends an interface with getters that have generic type.
REGRESSION. Last worked in version 7
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the test case under java 7
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
output from java 6:
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.6.0_22" class="java.beans.XMLDecoder">
<object class="test.Test$WorkingBean">
<void property="cod_id">
<int>99</int>
</void>
</object>
<object class="test.Test$BrokenBean">
<void property="cod_id">
<int>99</int>
</void>
</object>
</java>
ACTUAL -
cod_id doesn't get serialised
output from java 7:
java.lang.NoSuchMethodException: <unbound>=Test$BrokenBean.getCod_id();
Continuing ...
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.7.0" class="java.beans.XMLDecoder">
<object class="test.Test$WorkingBean">
<void property="cod_id">
<int>99</int>
</void>
</object>
<object class="test.Test$BrokenBean"/>
</java>
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NoSuchMethodException: <unbound>=Test$BrokenBean.getCod_id();
Continuing ...
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test;
import java.beans.XMLEncoder;
public class Test {
public static class WorkingBean {
private Integer cod_id;
public WorkingBean() {
}
public Integer getCod_id() {
return cod_id;
}
public void setCod_id(Integer cod_id) {
this.cod_id = cod_id;
}
}
public static class BrokenBean implements WithCodId<Integer> {
protected Integer cod_id;
public BrokenBean() {
}
public Integer getCod_id() {
return cod_id;
}
public void setCod_id(Integer cod_id) {
this.cod_id = cod_id;
}
}
public static interface WithCodId<T extends Number> {
T getCod_id();
void setCod_id(T value);
}
public static void main(String[] args) {
WorkingBean b1 = new WorkingBean();
b1.setCod_id(99);
BrokenBean b2 = new BrokenBean();
b2.setCod_id(99);
XMLEncoder enc = new XMLEncoder(System.out);
enc.writeObject(b1);
enc.writeObject(b2);
enc.close();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Hardcode type in the WithCodId interface.
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Confirmed under Windows Vista and 7 32bit, XP and 64bit untested
A DESCRIPTION OF THE PROBLEM :
XMLEncoder fails to encode a bean when it extends an interface with getters that have generic type.
REGRESSION. Last worked in version 7
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the test case under java 7
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
output from java 6:
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.6.0_22" class="java.beans.XMLDecoder">
<object class="test.Test$WorkingBean">
<void property="cod_id">
<int>99</int>
</void>
</object>
<object class="test.Test$BrokenBean">
<void property="cod_id">
<int>99</int>
</void>
</object>
</java>
ACTUAL -
cod_id doesn't get serialised
output from java 7:
java.lang.NoSuchMethodException: <unbound>=Test$BrokenBean.getCod_id();
Continuing ...
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.7.0" class="java.beans.XMLDecoder">
<object class="test.Test$WorkingBean">
<void property="cod_id">
<int>99</int>
</void>
</object>
<object class="test.Test$BrokenBean"/>
</java>
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NoSuchMethodException: <unbound>=Test$BrokenBean.getCod_id();
Continuing ...
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package test;
import java.beans.XMLEncoder;
public class Test {
public static class WorkingBean {
private Integer cod_id;
public WorkingBean() {
}
public Integer getCod_id() {
return cod_id;
}
public void setCod_id(Integer cod_id) {
this.cod_id = cod_id;
}
}
public static class BrokenBean implements WithCodId<Integer> {
protected Integer cod_id;
public BrokenBean() {
}
public Integer getCod_id() {
return cod_id;
}
public void setCod_id(Integer cod_id) {
this.cod_id = cod_id;
}
}
public static interface WithCodId<T extends Number> {
T getCod_id();
void setCod_id(T value);
}
public static void main(String[] args) {
WorkingBean b1 = new WorkingBean();
b1.setCod_id(99);
BrokenBean b2 = new BrokenBean();
b2.setCod_id(99);
XMLEncoder enc = new XMLEncoder(System.out);
enc.writeObject(b1);
enc.writeObject(b2);
enc.close();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Hardcode type in the WithCodId interface.
- backported by
-
JDK-2216481 XMLEncoder fails to encode and breaks backward compatibility
- Closed
- duplicates
-
JDK-7095555 java.lang.NoSuchMethodException in java.beans.Statement.invokeInternal
- Closed
- relates to
-
JDK-7108495 [macosx] JRE 1.7: Introspector.getBeanInfo cannot introspect JSR14 class
- Closed
-
JDK-8013416 Java Bean Persistence with XMLEncoder
- Resolved