harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r377729 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src: main/java/java/nio/charset/ test/java/org/apache/harmony/tests/java/nio/charset/
Date Tue, 14 Feb 2006 14:02:31 GMT
Author: tellison
Date: Tue Feb 14 06:02:21 2006
New Revision: 377729

URL: http://svn.apache.org/viewcvs?rev=377729&view=rev
Log:
Fix for
    HARMONY-33 (java.nio.BufferOverflow exception while decoding ByteBuffer with UTF-16 charset)
which is dup'ed by
    HARMONY-67 (java.nio.charset.Charset.decode(ByteBuffer) throws unexpected BufferOverflowException
for UTF-16BE, UTF-16LE, UTF-16 charsets.)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/AllTests.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java?rev=377729&r1=377728&r2=377729&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java
Tue Feb 14 06:02:21 2006
@@ -403,8 +403,12 @@
 			if (action == CodingErrorAction.IGNORE) {
 				continue;
 			} else if (action == CodingErrorAction.REPLACE) {
-				out.put(replace);
-				continue;
+				if (out.remaining() < replace.length()) {
+					result = CoderResult.OVERFLOW;
+				} else {
+					out.put(replace);
+					continue;
+				}
 			}
 			break;
 		}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/AllTests.java?rev=377729&r1=377728&r2=377729&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/AllTests.java
Tue Feb 14 06:02:21 2006
@@ -29,6 +29,7 @@
 				"Test for org.apache.harmony.tests.java.nio.charset");
 		//$JUnit-BEGIN$
 		suite.addTestSuite(CharsetTest.class);
+		suite.addTestSuite(CharsetDecoderTest.class);
 		//$JUnit-END$
 		return suite;
 	}

Added: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java?rev=377729&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java
Tue Feb 14 06:02:21 2006
@@ -0,0 +1,53 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+package org.apache.harmony.tests.java.nio.charset;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CodingErrorAction;
+
+import junit.framework.TestCase;
+
+public class CharsetDecoderTest extends TestCase {
+
+	/**
+	 * @tests java.nio.charset.CharsetDecoder#decode(java.nio.ByteBuffer)
+	 */
+	public static void test_decode() throws CharacterCodingException {
+		// Regression for HARMONY-33
+		ByteBuffer bb = ByteBuffer.allocate(1);
+		bb.put(0, (byte) 77);
+		CharsetDecoder decoder = Charset.forName("UTF-16").newDecoder();
+		decoder.onMalformedInput(CodingErrorAction.REPLACE);
+		decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
+		decoder.decode(bb);
+
+		// Regression for HARMONY-67
+		byte[] b = new byte[] { (byte) 1 };
+		ByteBuffer buf = ByteBuffer.wrap(b);
+		CharBuffer charbuf = Charset.forName("UTF-16").decode(buf);
+		assertEquals("Assert 0: charset UTF-16", 1, charbuf.length());
+
+		charbuf = Charset.forName("UTF-16BE").decode(buf);
+		assertEquals("Assert 1: charset UTF-16BE", 0, charbuf.length());
+
+		charbuf = Charset.forName("UTF-16LE").decode(buf);
+		assertEquals("Assert 2: charset UTF16LE", 0, charbuf.length());
+	}
+}



Mime
View raw message