harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r1027821 - in /harmony/enhanced/java/branches/java6: ./ classlib/ classlib/depends/libs/ classlib/modules/beans/src/main/java/java/beans/ classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/ drlvm/ jdktools/
Date Wed, 27 Oct 2010 05:59:58 GMT
Author: hindessm
Date: Wed Oct 27 05:59:57 2010
New Revision: 1027821

URL: http://svn.apache.org/viewvc?rev=1027821&view=rev
Log:
Merge change from /harmony/enhanced/java/trunk@1022846:

  r1022846 | zhoukevin | 2010-10-15 08:25:09 +0100 (Fri, 15 Oct 2010) | 1 line
  
  java.beans.XMLEncoder/Decoder fails to process invalid chars. Add 2 test cases to reproduce
the problems

Modified:
    harmony/enhanced/java/branches/java6/   (props changed)
    harmony/enhanced/java/branches/java6/classlib/   (props changed)
    harmony/enhanced/java/branches/java6/classlib/depends/libs/   (props changed)
    harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/XMLDecoder.java
    harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java
    harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
    harmony/enhanced/java/branches/java6/drlvm/   (props changed)
    harmony/enhanced/java/branches/java6/jdktools/   (props changed)

Propchange: harmony/enhanced/java/branches/java6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Oct 27 05:59:57 2010
@@ -1,4 +1,4 @@
 /harmony/enhanced/java/branches/mrh:935751-941490
-/harmony/enhanced/java/trunk:929253-997624,997759,997980,997986,998010,998030,998619,998628,998759,998804,998822,999260,999286,999306,999591,999601,999623,999715-999716,999724,999793,1000005,1000169,1000213,1000229,1000231,1000233,1000240,1000245,1000248,1000265,1000527,1000689,1000696,1000699-1000700,1000705,1000708,1001065,1001080,1001153,1001187,1001490,1001609,1001638,1001652,1001723,1001741,1001744-1001745,1001751,1002080,1002189,1002476,1002480,1002488,1002506,1002511,1002592,1002736,1002971,1002988,1002990,1003089,1003094-1003095,1003109,1003513,1003744,1004471,1004624,1004837,1004906,1004908,1005084,1005391,1005441-1005442,1005648,1005651,1006115,1021745,1022064,1022390,1022493,1022832
+/harmony/enhanced/java/trunk:929253-997624,997759,997980,997986,998010,998030,998619,998628,998759,998804,998822,999260,999286,999306,999591,999601,999623,999715-999716,999724,999793,1000005,1000169,1000213,1000229,1000231,1000233,1000240,1000245,1000248,1000265,1000527,1000689,1000696,1000699-1000700,1000705,1000708,1001065,1001080,1001153,1001187,1001490,1001609,1001638,1001652,1001723,1001741,1001744-1001745,1001751,1002080,1002189,1002476,1002480,1002488,1002506,1002511,1002592,1002736,1002971,1002988,1002990,1003089,1003094-1003095,1003109,1003513,1003744,1004471,1004624,1004837,1004906,1004908,1005084,1005391,1005441-1005442,1005648,1005651,1006115,1021745,1022064,1022390,1022493,1022832,1022846
 /harmony/enhanced/trunk:476395-929252
 /incubator/harmony/enhanced/trunk:292550-476394

Propchange: harmony/enhanced/java/branches/java6/classlib/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Oct 27 05:59:57 2010
@@ -1,7 +1,7 @@
 /harmony/enhanced/classlib/trunk:713674-735919,765923-926091,926318-926838
 /harmony/enhanced/classlib/trunk/working_classlib:884014-884286
 /harmony/enhanced/java/branches/mrh/classlib:935751-941490
-/harmony/enhanced/java/trunk/classlib:929253-997624,997759,997980,997986,998010,998030,998619,998628,998759,998804,998822,999260,999286,999306,999591,999601,999623,999715-999716,999724,999793,1000005,1000169,1000213,1000229,1000231,1000233,1000240,1000245,1000248,1000265,1000527,1000689,1000696,1000699-1000700,1000705,1000708,1001065,1001080,1001153,1001187,1001490,1001609,1001638,1001652,1001723,1001741,1001744-1001745,1001751,1002080,1002189,1002476,1002480,1002488,1002506,1002511,1002592,1002736,1002971,1002988,1002990,1003089,1003094-1003095,1003109,1003513,1003744,1004471,1004624,1004837,1004906,1004908,1005084,1005391,1005441-1005442,1005648,1005651,1006115,1021745,1022064,1022390,1022493,1022832
+/harmony/enhanced/java/trunk/classlib:929253-997624,997759,997980,997986,998010,998030,998619,998628,998759,998804,998822,999260,999286,999306,999591,999601,999623,999715-999716,999724,999793,1000005,1000169,1000213,1000229,1000231,1000233,1000240,1000245,1000248,1000265,1000527,1000689,1000696,1000699-1000700,1000705,1000708,1001065,1001080,1001153,1001187,1001490,1001609,1001638,1001652,1001723,1001741,1001744-1001745,1001751,1002080,1002189,1002476,1002480,1002488,1002506,1002511,1002592,1002736,1002971,1002988,1002990,1003089,1003094-1003095,1003109,1003513,1003744,1004471,1004624,1004837,1004906,1004908,1005084,1005391,1005441-1005442,1005648,1005651,1006115,1021745,1022064,1022390,1022493,1022832,1022846
 /harmony/enhanced/trunk/classlib:476395-929252
 /harmony/enhanced/trunk/working_classlib:476396-920147
 /incubator/harmony/enhanced/trunk/classlib:292550-476394

Propchange: harmony/enhanced/java/branches/java6/classlib/depends/libs/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Oct 27 05:59:57 2010
@@ -1,4 +1,4 @@
 /harmony/enhanced/classlib/trunk/depends/libs:544451-926091
-/harmony/enhanced/java/trunk/classlib/depends/libs:929253-997624,997759,997980,997986,998010,998030,998619,998628,998759,998804,998822,999260,999286,999306,999591,999601,999623,999715-999716,999724,999793,1000005,1000169,1000213,1000229,1000231,1000233,1000240,1000245,1000248,1000265,1000527,1000689,1000696,1000699-1000700,1000705,1000708,1001065,1001080,1001153,1001187,1001490,1001609,1001638,1001652,1001723,1001741,1001744-1001745,1001751,1002080,1002189,1002476,1002480,1002488,1002506,1002511,1002592,1002736,1002971,1002988,1002990,1003089,1003094-1003095,1003109,1003513,1003744,1004471,1004624,1004837,1004906,1004908,1005084,1005391,1005441-1005442,1005648,1005651,1006115,1021745,1022064,1022390,1022493,1022832
+/harmony/enhanced/java/trunk/classlib/depends/libs:929253-997624,997759,997980,997986,998010,998030,998619,998628,998759,998804,998822,999260,999286,999306,999591,999601,999623,999715-999716,999724,999793,1000005,1000169,1000213,1000229,1000231,1000233,1000240,1000245,1000248,1000265,1000527,1000689,1000696,1000699-1000700,1000705,1000708,1001065,1001080,1001153,1001187,1001490,1001609,1001638,1001652,1001723,1001741,1001744-1001745,1001751,1002080,1002189,1002476,1002480,1002488,1002506,1002511,1002592,1002736,1002971,1002988,1002990,1003089,1003094-1003095,1003109,1003513,1003744,1004471,1004624,1004837,1004906,1004908,1005084,1005391,1005441-1005442,1005648,1005651,1006115,1021745,1022064,1022390,1022493,1022832,1022846
 /harmony/enhanced/trunk/classlib/depends/libs:476395-929252
 /incubator/harmony/enhanced/trunk/classlib/depends/libs:292550-476394

Modified: harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/XMLDecoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/XMLDecoder.java?rev=1027821&r1=1027820&r2=1027821&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/XMLDecoder.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/XMLDecoder.java
Wed Oct 27 05:59:57 2010
@@ -111,6 +111,7 @@ public class XMLDecoder {
             elem.isExpression = true;
             elem.id = attributes.getValue("id");
             elem.idref = attributes.getValue("idref");
+            elem.attributes = attributes;
             if (elem.idref == null) {
                 obtainTarget(elem, attributes);
                 obtainMethod(elem, attributes);
@@ -201,6 +202,7 @@ public class XMLDecoder {
             Elem elem = new Elem();
             elem.isExpression = true;
             elem.id = attributes.getValue("id"); //$NON-NLS-1$
+            elem.attributes = attributes;
             try {
                 // find component class
                 Class<?> compClass = classForName(attributes.getValue("class")); //$NON-NLS-1$
@@ -230,6 +232,7 @@ public class XMLDecoder {
         private void startVoidElem(Attributes attributes) {
             Elem elem = new Elem();
             elem.id = attributes.getValue("id");
+            elem.attributes = attributes;
             obtainTarget(elem, attributes);
             obtainMethod(elem, attributes);
             readObjs.push(elem);
@@ -242,6 +245,7 @@ public class XMLDecoder {
             elem.isExpression = true;
             elem.id = attributes.getValue("id");
             elem.idref = attributes.getValue("idref");
+            elem.attributes = attributes;
             elem.target = tagName;
             readObjs.push(elem);
         }
@@ -258,6 +262,21 @@ public class XMLDecoder {
             }
             // find the elem to close
             Elem toClose = latestUnclosedElem();
+            if ("string".equals(toClose.target)) {
+                StringBuilder sb = new StringBuilder();
+                for (int index = readObjs.size() - 1; index >= 0; index--) {
+                    Elem elem = (Elem) readObjs.get(index);
+                    if (toClose == elem) {
+                        break;
+                    }
+                    if ("char".equals(elem.target)) {
+                        sb.insert(0, elem.methodName);
+                    }
+                }
+                toClose.methodName = toClose.methodName != null ? toClose.methodName
+                        + sb.toString()
+                        : sb.toString();
+            }
             // make sure it is executed
             execute(toClose);
             // set to closed
@@ -465,6 +484,15 @@ public class XMLDecoder {
             } else if ("byte".equals(tag)) {
                 return Byte.valueOf(value);
             } else if ("char".equals(tag)) {
+                if (value == null && elem.attributes != null) {
+                    String codeAttr = elem.attributes.getValue("code");
+                    if (codeAttr != null) {
+                        Character character = new Character((char) Integer
+                                .valueOf(codeAttr.substring(1), 16).intValue());
+                        elem.methodName = character.toString();
+                        return character;
+                    }
+                }
                 return Character.valueOf(value.charAt(0));
             } else if ("double".equals(tag)) {
                 return Double.valueOf(value);
@@ -522,6 +550,8 @@ public class XMLDecoder {
 
         boolean fromOwner;
 
+        Attributes attributes;
+
         Object result;
 
     }

Modified: harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java?rev=1027821&r1=1027820&r2=1027821&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/beans/src/main/java/java/beans/XMLEncoder.java
Wed Oct 27 05:59:57 2010
@@ -219,7 +219,13 @@ public class XMLEncoder extends Encoder 
         } else if (obj instanceof Byte) {
             out.println("<byte>" + obj + "</byte> ");
         } else if (obj instanceof Character) {
-            out.println("<char>" + obj + "</char> ");
+            char objChar = ((Character) obj).charValue();
+            if (invalidCharacter(objChar)) {
+                out.println("<char code=\"#" + Integer.toString(objChar, 16)
+                        + "\"/>");
+            } else {
+                out.println("<char>" + objChar + "</char> ");
+            }
         } else if (obj instanceof Double) {
             out.println("<double>" + obj + "</double> ");
         } else if (obj instanceof Float) {
@@ -236,6 +242,11 @@ public class XMLEncoder extends Encoder 
         }
     }
 
+    private boolean invalidCharacter(char c) {
+        return ((0x0000 <= c && c < 0x0009) || (0x000a < c && c
< 0x000d)
+                || (0x000d < c && c < 0x0020) || (0xd7ff < c &&
c < 0xe000) || c == 0xfffe);
+    }
+
     @SuppressWarnings("nls")
     private void flushExpression(Object obj, Record rec, int indent,
             boolean asStatement) {
@@ -612,7 +623,12 @@ public class XMLEncoder extends Encoder 
             } else if (c == '"') {
                 out.print("&quot;");
             } else {
-                out.print(c);
+                if (invalidCharacter(c)) {
+                    out.print("<char code=\"#" + Integer.toString(c, 16)
+                            + "\"/>");
+                } else {
+                    out.print(c);
+                }
             }
         }
     }

Modified: harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java?rev=1027821&r1=1027820&r2=1027821&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
Wed Oct 27 05:59:57 2010
@@ -25,6 +25,7 @@ import java.beans.ExceptionListener;
 import java.beans.Expression;
 import java.beans.PersistenceDelegate;
 import java.beans.Statement;
+import java.beans.XMLDecoder;
 import java.beans.XMLEncoder;
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
@@ -1057,4 +1058,106 @@ public class XMLEncoderTest extends Test
             this.name = name;
         }
     }
+
+    public static class MockCharProperty {
+        private char property;
+
+        public char getProperty() {
+            return property;
+        }
+
+        public void setProperty(char property) {
+            this.property = property;
+        }
+
+        public boolean equals(Object obj) {
+            if (obj instanceof MockCharProperty) {
+                return ((MockCharProperty) obj).property == (this.property);
+            }
+            return false;
+        }
+    }
+
+    public void testMockCharProperty() {
+        MockCharProperty expectedObj = new MockCharProperty();
+        MockCharProperty actualObj;
+        ByteArrayOutputStream baos;
+        ByteArrayInputStream bais;
+        XMLEncoder xmlEncoder;
+        XMLDecoder xmlDecoder;
+        char ch;
+        for (int index = 1; index < 65536; index++) {
+            ch = (char) index;
+            if (invalidCharacter(ch)) {
+                expectedObj.setProperty(ch);
+                baos = new ByteArrayOutputStream();
+                xmlEncoder = new XMLEncoder(baos);
+                xmlEncoder.writeObject(expectedObj);
+                xmlEncoder.close();
+                assertTrue(baos.toString().contains("<char code=\"#"));
+
+                bais = new ByteArrayInputStream(baos.toByteArray());
+                xmlDecoder = new XMLDecoder(bais);
+                actualObj = (MockCharProperty) xmlDecoder.readObject();
+                xmlDecoder.close();
+                assertEquals(expectedObj, actualObj);
+            }
+        }
+    }
+
+    public static class MockStringProperty {
+        private String property;
+
+        public String getProperty() {
+            return property;
+        }
+
+        public void setProperty(String property) {
+            this.property = property;
+        }
+
+        public boolean equals(Object obj) {
+            if (obj instanceof MockStringProperty) {
+                return ((MockStringProperty) obj).property
+                        .equals(this.property);
+            }
+            return false;
+        }
+    }
+
+    public void testMockStringProperty() {
+        MockStringProperty expectedObj = new MockStringProperty();
+        MockStringProperty actualObj;
+        ByteArrayOutputStream baos;
+        ByteArrayInputStream bais;
+        XMLEncoder xmlEncoder;
+        XMLDecoder xmlDecoder;
+        char ch;
+        for (int index = 0; index < 65536; index++) {
+            ch = (char) index;
+            if (invalidCharacter(ch)) {
+                expectedObj.setProperty(stringWithChar(ch));
+                baos = new ByteArrayOutputStream();
+                xmlEncoder = new XMLEncoder(baos);
+                xmlEncoder.writeObject(expectedObj);
+                xmlEncoder.close();
+                assertTrue(baos.toString().contains("<char code=\"#"));
+
+                bais = new ByteArrayInputStream(baos.toByteArray());
+                xmlDecoder = new XMLDecoder(bais);
+                actualObj = (MockStringProperty) xmlDecoder.readObject();
+                xmlDecoder.close();
+                assertEquals(expectedObj, actualObj);
+            }
+        }
+    }
+
+    private String stringWithChar(char character) {
+        return "a string with a " + character + " character";
+    }
+
+    private boolean invalidCharacter(char c) {
+        return ((0x0000 <= c && c < 0x0009) || (0x000a < c && c
< 0x000d)
+                || (0x000d < c && c < 0x0020) || (0xd7ff < c &&
c < 0xe000) || c == 0xfffe);
+    }
 }
\ No newline at end of file

Propchange: harmony/enhanced/java/branches/java6/drlvm/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Oct 27 05:59:57 2010
@@ -1,5 +1,5 @@
 /harmony/enhanced/java/branches/mrh/drlvm:935751-941490
-/harmony/enhanced/java/trunk/drlvm:929253-997624,997759,997980,997986,998010,998030,998619,998628,998759,998804,998822,999260,999286,999306,999591,999601,999623,999715-999716,999724,999793,1000005,1000169,1000213,1000229,1000231,1000233,1000240,1000245,1000248,1000265,1000527,1000689,1000696,1000699-1000700,1000705,1000708,1001065,1001080,1001153,1001187,1001490,1001609,1001638,1001652,1001723,1001741,1001744-1001745,1001751,1002080,1002189,1002476,1002480,1002488,1002506,1002511,1002592,1002736,1002971,1002988,1002990,1003089,1003094-1003095,1003109,1003513,1003744,1004471,1004624,1004837,1004906,1004908,1005084,1005391,1005441-1005442,1005648,1005651,1006115,1021745,1022064,1022390,1022493,1022832
+/harmony/enhanced/java/trunk/drlvm:929253-997624,997759,997980,997986,998010,998030,998619,998628,998759,998804,998822,999260,999286,999306,999591,999601,999623,999715-999716,999724,999793,1000005,1000169,1000213,1000229,1000231,1000233,1000240,1000245,1000248,1000265,1000527,1000689,1000696,1000699-1000700,1000705,1000708,1001065,1001080,1001153,1001187,1001490,1001609,1001638,1001652,1001723,1001741,1001744-1001745,1001751,1002080,1002189,1002476,1002480,1002488,1002506,1002511,1002592,1002736,1002971,1002988,1002990,1003089,1003094-1003095,1003109,1003513,1003744,1004471,1004624,1004837,1004906,1004908,1005084,1005391,1005441-1005442,1005648,1005651,1006115,1021745,1022064,1022390,1022493,1022832,1022846
 /harmony/enhanced/trunk/drlvm:476395-929252
 /harmony/enhanced/trunk/working_vm:476396-920147
 /incubator/harmony/enhanced/trunk/drlvm:292550-476394

Propchange: harmony/enhanced/java/branches/java6/jdktools/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Oct 27 05:59:57 2010
@@ -1,4 +1,4 @@
-/harmony/enhanced/java/trunk/jdktools:929253-997624,997759,997980,997986,998010,998030,998619,998628,998759,998804,998822,999260,999286,999306,999591,999601,999623,999715-999716,999724,999793,1000005,1000169,1000213,1000229,1000231,1000233,1000240,1000245,1000248,1000265,1000527,1000689,1000696,1000699-1000700,1000705,1000708,1001065,1001080,1001153,1001187,1001490,1001609,1001638,1001652,1001723,1001741,1001744-1001745,1001751,1002080,1002189,1002476,1002480,1002488,1002506,1002511,1002592,1002736,1002971,1002988,1002990,1003089,1003094-1003095,1003109,1003513,1003744,1004471,1004624,1004837,1004906,1004908,1005084,1005391,1005441-1005442,1005648,1005651,1006115,1021745,1022064,1022390,1022493,1022832
+/harmony/enhanced/java/trunk/jdktools:929253-997624,997759,997980,997986,998010,998030,998619,998628,998759,998804,998822,999260,999286,999306,999591,999601,999623,999715-999716,999724,999793,1000005,1000169,1000213,1000229,1000231,1000233,1000240,1000245,1000248,1000265,1000527,1000689,1000696,1000699-1000700,1000705,1000708,1001065,1001080,1001153,1001187,1001490,1001609,1001638,1001652,1001723,1001741,1001744-1001745,1001751,1002080,1002189,1002476,1002480,1002488,1002506,1002511,1002592,1002736,1002971,1002988,1002990,1003089,1003094-1003095,1003109,1003513,1003744,1004471,1004624,1004837,1004906,1004908,1005084,1005391,1005441-1005442,1005648,1005651,1006115,1021745,1022064,1022390,1022493,1022832,1022846
 /harmony/enhanced/jdktools/trunk:630107-925933
 /harmony/enhanced/trunk/jdktools:476395-929252
 /harmony/enhanced/trunk/working_jdktools:476396-920147



Mime
View raw message