You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by zh...@apache.org on 2010/04/08 09:04:38 UTC
svn commit: r931796 - in
/harmony/enhanced/java/trunk/classlib/modules/beans/src:
main/java/java/beans/ test/java/org/apache/harmony/beans/tests/java/beans/
test/resources/xml/
Author: zhoukevin
Date: Thu Apr 8 07:04:38 2010
New Revision: 931796
URL: http://svn.apache.org/viewvc?rev=931796&view=rev
Log:
1. Apply patch for HARMONY-6221: java.beans.XMLEncoder.writeObject(obj) outputs different contents of the modified field of super class from RI and add a test case
2. Fix a problem in previous test resource file: /xml/MockBean4Codec_ManyChanges.xml
Added:
harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/ClassID.xml
Modified:
harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java
harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockBean4Codec_ManyChanges.xml
Modified: harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java?rev=931796&r1=931795&r2=931796&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java (original)
+++ harmony/enhanced/java/trunk/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java Thu Apr 8 07:04:38 2010
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package java.beans;
import java.io.OutputStream;
@@ -201,9 +200,9 @@ public class XMLEncoder extends Encoder
out.print("<string>");
flushString((String) obj);
out.println("</string>");
- } else if (obj instanceof Class) {
+ } else if (obj instanceof Class<?>) {
out.print("<class>");
- out.print(((Class) obj).getName());
+ out.print(((Class<?>) obj).getName());
out.println("</class>");
} else if (obj instanceof Boolean) {
out.print("<boolean>");
@@ -361,7 +360,7 @@ public class XMLEncoder extends Encoder
// class & length
out.print(" class=\"");
- out.print(((Class) stat.getArguments()[0]).getName());
+ out.print(((Class<?>) stat.getArguments()[0]).getName());
out.print("\" length=\"");
out.print(stat.getArguments()[1]);
out.print("\"");
@@ -398,9 +397,9 @@ public class XMLEncoder extends Encoder
}
// special class attribute
- if (stat.getTarget() instanceof Class) {
+ if (stat.getTarget() instanceof Class<?>) {
out.print(" class=\"");
- out.print(((Class) stat.getTarget()).getName());
+ out.print(((Class<?>) stat.getTarget()).getName());
out.print("\"");
}
@@ -525,9 +524,9 @@ public class XMLEncoder extends Encoder
}
// special class attribute
- if (stat.getTarget() instanceof Class) {
+ if (stat.getTarget() instanceof Class<?>) {
out.print(" class=\"");
- out.print(((Class) stat.getTarget()).getName());
+ out.print(((Class<?>) stat.getTarget()).getName());
out.print("\"");
}
@@ -575,9 +574,9 @@ public class XMLEncoder extends Encoder
}
// special class attribute
- if (stat.getTarget() instanceof Class) {
+ if (stat.getTarget() instanceof Class<?>) {
out.print(" class=\"");
- out.print(((Class) stat.getTarget()).getName());
+ out.print(((Class<?>) stat.getTarget()).getName());
out.print("\"");
}
@@ -661,7 +660,7 @@ public class XMLEncoder extends Encoder
private boolean isBasicType(Object value) {
return value == null || value instanceof Boolean
|| value instanceof Byte || value instanceof Character
- || value instanceof Class || value instanceof Double
+ || value instanceof Class<?> || value instanceof Double
|| value instanceof Float || value instanceof Integer
|| value instanceof Long || value instanceof Short
|| value instanceof String || value instanceof Proxy;
@@ -697,44 +696,44 @@ public class XMLEncoder extends Encoder
return name.substring(i + 1);
}
- /*
- * The preprocess removes unused statements and counts references of every
- * object
- */
- private void preprocess(Object obj, Record rec) {
- if (isBasicType(obj) && writingObject) {
- return;
- }
+ /*
+ * The preprocess removes unused statements and counts references of every
+ * object
+ */
+ private void preprocess(Object obj, Record rec) {
+ if (writingObject && isBasicType(obj)) {
+ return;
+ }
- // count reference
- rec.refCount++;
+ if (obj instanceof Class<?>) {
+ return;
+ }
- // do things only one time for each record
- if (rec.refCount > 1) {
- return;
- }
+ // count reference
+ rec.refCount++;
- // deal with 'field' property
- try {
- if (isStaticConstantsSupported
- && "getField".equals(((Record) records.get(rec.exp //$NON-NLS-1$
- .getTarget())).exp.getMethodName())) {
- records.remove(obj);
- }
- } catch (NullPointerException e) {
- // do nothing, safely
- }
+ // do things only one time for each record
+ if (rec.refCount > 1) {
+ return;
+ }
- // do it recursively
- if (null != rec.exp) {
- Object args[] = rec.exp.getArguments();
- for (int i = 0; i < args.length; i++) {
- Record argRec = (Record) records.get(args[i]);
- if (argRec != null) {
- preprocess(args[i], argRec);
- }
- }
- }
+ // do it recursively
+ if (null != rec.exp) {
+ // deal with 'field' property
+ Record targetRec = (Record) records.get(rec.exp.getTarget());
+ if (targetRec != null && targetRec.exp != null
+ && "getField".equals(targetRec.exp.getMethodName())) {
+ records.remove(obj);
+ }
+
+ Object args[] = rec.exp.getArguments();
+ for (int i = 0; i < args.length; i++) {
+ Record argRec = (Record) records.get(args[i]);
+ if (argRec != null) {
+ preprocess(args[i], argRec);
+ }
+ }
+ }
for (Iterator<?> iter = rec.stats.iterator(); iter.hasNext();) {
Statement subStat = (Statement) iter.next();
@@ -917,6 +916,7 @@ public class XMLEncoder extends Encoder
* Records the object so that it can be written out later, then calls super
* implementation.
*/
+ @SuppressWarnings("unchecked")
@Override
public void writeObject(Object o) {
synchronized (this) {
Modified: harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java?rev=931796&r1=931795&r2=931796&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java (original)
+++ harmony/enhanced/java/trunk/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java Thu Apr 8 07:04:38 2010
@@ -35,6 +35,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringReader;
+import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
@@ -903,4 +904,30 @@ public class XMLEncoderTest extends Test
this.name = name;
}
}
+
+ public void testWriteObject_ClassID() throws Exception {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ XMLEncoder xmlEncoder = new XMLEncoder(bos);
+ ChildClass childClazz = new ChildClass();
+ childClazz.setClazz(ChildClass.class);
+ xmlEncoder.writeObject(childClazz);
+ xmlEncoder.close();
+ assertXMLContent(null, bos.toByteArray(), "/xml/ClassID.xml");
+ }
+
+ public static class ParentClass {
+
+ Class<?> clazz = Collection.class;
+
+ public Class<?> getClazz() {
+ return clazz;
+ }
+
+ public void setClazz(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+ }
+
+ public static class ChildClass extends ParentClass {
+ }
}
\ No newline at end of file
Added: harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/ClassID.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/ClassID.xml?rev=931796&view=auto
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/ClassID.xml (added)
+++ harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/ClassID.xml Thu Apr 8 07:04:38 2010
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<java version="${version}" class="java.beans.XMLDecoder">
+ <object class="org.apache.harmony.beans.tests.java.beans.XMLEncoderTest$ChildClass">
+ <void property="clazz">
+ <class>org.apache.harmony.beans.tests.java.beans.XMLEncoderTest$ChildClass</class>
+ </void>
+ </object>
+</java>
+
Modified: harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockBean4Codec_ManyChanges.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockBean4Codec_ManyChanges.xml?rev=931796&r1=931795&r2=931796&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockBean4Codec_ManyChanges.xml (original)
+++ harmony/enhanced/java/trunk/classlib/modules/beans/src/test/resources/xml/MockBean4Codec_ManyChanges.xml Thu Apr 8 07:04:38 2010
@@ -48,7 +48,7 @@
<float>12.34</float>
</void>
<void property="friend">
- <object class="${classname}" id="MockBean4Codec1">
+ <object class="${classname}">
<void property="clazz">
<class>${classname}</class>
</void>