提交 5b33ae62 编写于 作者: M malenkov

8013557: XMLEncoder in 1.7 can't encode objects initialized in no argument constructor

Reviewed-by: alexsch
上级 f6ad0fbd
...@@ -487,6 +487,12 @@ public class XMLEncoder extends Encoder implements AutoCloseable { ...@@ -487,6 +487,12 @@ public class XMLEncoder extends Encoder implements AutoCloseable {
} }
indentation--; indentation--;
Statement statement = getMissedStatement();
while (statement != null) {
outputStatement(statement, this, false);
statement = getMissedStatement();
}
try { try {
out.flush(); out.flush();
} }
...@@ -503,6 +509,17 @@ public class XMLEncoder extends Encoder implements AutoCloseable { ...@@ -503,6 +509,17 @@ public class XMLEncoder extends Encoder implements AutoCloseable {
targetToStatementList.clear(); targetToStatementList.clear();
} }
Statement getMissedStatement() {
for (List<Statement> statements : this.targetToStatementList.values()) {
for (int i = 0; i < statements.size(); i++) {
if (Statement.class == statements.get(i).getClass()) {
return statements.remove(i);
}
}
}
return null;
}
/** /**
* This method calls <code>flush</code>, writes the closing * This method calls <code>flush</code>, writes the closing
...@@ -597,7 +614,7 @@ public class XMLEncoder extends Encoder implements AutoCloseable { ...@@ -597,7 +614,7 @@ public class XMLEncoder extends Encoder implements AutoCloseable {
"methodName") + " should not be null"); "methodName") + " should not be null");
} }
if (target instanceof Field && methodName.equals("get")) { if (isArgument && target instanceof Field && methodName.equals("get")) {
Field f = (Field)target; Field f = (Field)target;
writeln("<object class=" + quote(f.getDeclaringClass().getName()) + writeln("<object class=" + quote(f.getDeclaringClass().getName()) +
" field=" + quote(f.getName()) + "/>"); " field=" + quote(f.getName()) + "/>");
......
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6989223
* @summary Tests Rectangle2D.Double encoding
* @author Sergey Malenkov
*/
import java.awt.geom.Rectangle2D;
public class Test6989223 extends AbstractTest {
public static void main(String[] args) {
new Test6989223().test(true);
}
protected Object getObject() {
return new Bean(1, 2, 3, 4);
}
@Override
protected Object getAnotherObject() {
return new Bean(1, 2, 3, 5);
}
public static class Bean extends Rectangle2D.Double {
public Bean() {
}
public Bean(double x, double y, double w, double h) {
super(x, y, w, h);
}
@Override
public boolean equals(Object object) {
return super.equals(object); // to avoid recursion during validation
}
}
}
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7080156 7094245
* @summary Tests beans with public arrays
* @author Sergey Malenkov
*/
public class Test7080156 extends AbstractTest {
public static void main(String[] args) {
new Test7080156().test(true);
}
protected Object getObject() {
Bean bean = new Bean();
bean.setArray("something");
return bean;
}
@Override
protected Object getAnotherObject() {
Bean bean = new Bean();
bean.setArray("some", "thing");
return bean;
}
public static class Bean {
public String[] array = {"default"};
public void setArray(String... array) {
this.array = array;
}
public String[] getArray() {
return this.array;
}
}
}
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8013557
* @summary Tests beans with public fields
* @author Sergey Malenkov
*/
public class Test8013557 extends AbstractTest {
public static void main(String[] args) {
new Test8013557().test(true);
}
protected Object getObject() {
return new Bean(new Value("something"));
}
@Override
protected Object getAnotherObject() {
return new Bean(new Value());
}
public static class Bean {
public Value value;
public Bean() {
this.value = new Value();
}
public Bean(Value value) {
this.value = value;
}
public void setValue(Value value) {
this.value = value;
}
public Value getValue() {
return this.value;
}
}
public static class Value {
private String string;
public Value() {
this.string = "default";
}
public Value(String value) {
this.string = value;
}
public void setString(String string) {
this.string = string;
}
public String getString() {
return this.string;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册