6479191: LTP: XMLEncoder does not update initialized property of GridBagConstraints type
Reviewed-by: rupashka
This commit is contained in:
parent
3ee6427a9c
commit
cd6f30d3bc
@ -222,6 +222,25 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate {
|
||||
|
||||
// Write out the properties of this instance.
|
||||
private void initBean(Class type, Object oldInstance, Object newInstance, Encoder out) {
|
||||
for (Field field : type.getFields()) {
|
||||
int mod = field.getModifiers();
|
||||
if (Modifier.isFinal(mod) || Modifier.isStatic(mod) || Modifier.isTransient(mod)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
Expression oldGetExp = new Expression(field, "get", new Object[] { oldInstance });
|
||||
Expression newGetExp = new Expression(field, "get", new Object[] { newInstance });
|
||||
Object oldValue = oldGetExp.getValue();
|
||||
Object newValue = newGetExp.getValue();
|
||||
out.writeExpression(oldGetExp);
|
||||
if (!equals(newValue, out.get(oldValue))) {
|
||||
out.writeStatement(new Statement(field, "set", new Object[] { oldInstance, oldValue }));
|
||||
}
|
||||
}
|
||||
catch (Exception exception) {
|
||||
out.getExceptionListener().exceptionThrown(exception);
|
||||
}
|
||||
}
|
||||
BeanInfo info;
|
||||
try {
|
||||
info = Introspector.getBeanInfo(type);
|
||||
|
@ -700,56 +700,6 @@ class java_beans_beancontext_BeanContextSupport_PersistenceDelegate extends java
|
||||
|
||||
// AWT
|
||||
|
||||
/**
|
||||
* The persistence delegate for {@link Dimension}.
|
||||
* It is impossible to use {@link DefaultPersistenceDelegate}
|
||||
* because all getters have return types that differ from parameter types
|
||||
* of the constructor {@link Dimension#Dimension(int, int)}.
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class java_awt_Dimension_PersistenceDelegate extends PersistenceDelegate {
|
||||
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
|
||||
return oldInstance.equals(newInstance);
|
||||
}
|
||||
|
||||
protected Expression instantiate(Object oldInstance, Encoder out) {
|
||||
Dimension dimension = (Dimension) oldInstance;
|
||||
Object[] args = new Object[] {
|
||||
dimension.width,
|
||||
dimension.height,
|
||||
};
|
||||
return new Expression(dimension, dimension.getClass(), "new", args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The persistence delegate for {@link GridBagConstraints}.
|
||||
* It is impossible to use {@link DefaultPersistenceDelegate}
|
||||
* because this class does not have any properties.
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class java_awt_GridBagConstraints_PersistenceDelegate extends PersistenceDelegate {
|
||||
protected Expression instantiate(Object oldInstance, Encoder out) {
|
||||
GridBagConstraints gbc = (GridBagConstraints) oldInstance;
|
||||
Object[] args = new Object[] {
|
||||
gbc.gridx,
|
||||
gbc.gridy,
|
||||
gbc.gridwidth,
|
||||
gbc.gridheight,
|
||||
gbc.weightx,
|
||||
gbc.weighty,
|
||||
gbc.anchor,
|
||||
gbc.fill,
|
||||
gbc.insets,
|
||||
gbc.ipadx,
|
||||
gbc.ipady,
|
||||
};
|
||||
return new Expression(gbc, gbc.getClass(), "new", args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The persistence delegate for {@link Insets}.
|
||||
* It is impossible to use {@link DefaultPersistenceDelegate}
|
||||
@ -774,54 +724,6 @@ final class java_awt_Insets_PersistenceDelegate extends PersistenceDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The persistence delegate for {@link Point}.
|
||||
* It is impossible to use {@link DefaultPersistenceDelegate}
|
||||
* because all getters have return types that differ from parameter types
|
||||
* of the constructor {@link Point#Point(int, int)}.
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class java_awt_Point_PersistenceDelegate extends PersistenceDelegate {
|
||||
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
|
||||
return oldInstance.equals(newInstance);
|
||||
}
|
||||
|
||||
protected Expression instantiate(Object oldInstance, Encoder out) {
|
||||
Point point = (Point) oldInstance;
|
||||
Object[] args = new Object[] {
|
||||
point.x,
|
||||
point.y,
|
||||
};
|
||||
return new Expression(point, point.getClass(), "new", args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The persistence delegate for {@link Rectangle}.
|
||||
* It is impossible to use {@link DefaultPersistenceDelegate}
|
||||
* because all getters have return types that differ from parameter types
|
||||
* of the constructor {@link Rectangle#Rectangle(int, int, int, int)}.
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class java_awt_Rectangle_PersistenceDelegate extends PersistenceDelegate {
|
||||
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
|
||||
return oldInstance.equals(newInstance);
|
||||
}
|
||||
|
||||
protected Expression instantiate(Object oldInstance, Encoder out) {
|
||||
Rectangle rectangle = (Rectangle) oldInstance;
|
||||
Object[] args = new Object[] {
|
||||
rectangle.x,
|
||||
rectangle.y,
|
||||
rectangle.width,
|
||||
rectangle.height,
|
||||
};
|
||||
return new Expression(rectangle, rectangle.getClass(), "new", args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The persistence delegate for {@link Font}.
|
||||
* It is impossible to use {@link DefaultPersistenceDelegate}
|
||||
|
@ -407,7 +407,20 @@ public class XMLEncoder extends Encoder {
|
||||
os.writeObject(this);
|
||||
*/
|
||||
mark(oldStm);
|
||||
statementList(oldStm.getTarget()).add(oldStm);
|
||||
Object target = oldStm.getTarget();
|
||||
if (target instanceof Field) {
|
||||
String method = oldStm.getMethodName();
|
||||
Object[] args = oldStm.getArguments();
|
||||
if ((method == null) || (args == null)) {
|
||||
}
|
||||
else if (method.equals("get") && (args.length == 1)) {
|
||||
target = args[0];
|
||||
}
|
||||
else if (method.equals("set") && (args.length == 2)) {
|
||||
target = args[0];
|
||||
}
|
||||
}
|
||||
statementList(target).add(oldStm);
|
||||
}
|
||||
catch (Exception e) {
|
||||
getExceptionListener().exceptionThrown(new Exception("XMLEncoder: discarding statement " + oldStm, e));
|
||||
@ -703,7 +716,9 @@ public class XMLEncoder extends Encoder {
|
||||
statements.add(exp);
|
||||
}
|
||||
outputValue(target, outer, false);
|
||||
outputValue(value, outer, isArgument);
|
||||
if (expression) {
|
||||
outputValue(value, outer, isArgument);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (expression && (d.refs > 1)) {
|
||||
@ -722,8 +737,10 @@ public class XMLEncoder extends Encoder {
|
||||
}
|
||||
else if ((!expression && methodName.startsWith("set") && args.length == 1) ||
|
||||
(expression && methodName.startsWith("get") && args.length == 0)) {
|
||||
attributes = attributes + " property=" +
|
||||
quote(Introspector.decapitalize(methodName.substring(3)));
|
||||
if (3 < methodName.length()) {
|
||||
attributes = attributes + " property=" +
|
||||
quote(Introspector.decapitalize(methodName.substring(3)));
|
||||
}
|
||||
}
|
||||
else if (!methodName.equals("new") && !methodName.equals("newInstance")) {
|
||||
attributes = attributes + " method=" + quote(methodName);
|
||||
|
@ -55,7 +55,6 @@ public final class java_awt_GridBagConstraints extends AbstractTest<GridBagConst
|
||||
}
|
||||
|
||||
protected GridBagConstraints getAnotherObject() {
|
||||
return null; // TODO: could not update property
|
||||
// return new GridBagConstraints();
|
||||
return new GridBagConstraints();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user