harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r378491 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src: main/java/java/nio/charset/CharsetDecoder.java test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java
Date Fri, 17 Feb 2006 11:53:46 GMT
Author: tellison
Date: Fri Feb 17 03:53:42 2006
New Revision: 378491

URL: http://svn.apache.org/viewcvs?rev=378491&view=rev
Log:
Fix for HARMONY-99 (java.nio.charset.CharsetDecoder.decode(ByteBuffer in) does not throw MalformedInputException
when buffer's current position is not legal)

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/CharsetDecoderTest.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=378491&r1=378490&r2=378491&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
Fri Feb 17 03:53:42 2006
@@ -227,8 +227,9 @@
 		reset();
 		int length = (int) (in.remaining() * averChars);
 		CharBuffer output = CharBuffer.allocate(length);
+		CoderResult result = null;
 		while (true) {
-			CoderResult result = decode(in, output, false);
+			result = decode(in, output, false);
 			if (result.isUnderflow()) {
 				break;
 			} else if (result.isMalformed()
@@ -240,7 +241,14 @@
 			}
 			output = allocateMore(output);
 		}
-		decode(in, output, true);
+		result = decode(in, output, true);
+		if (result.isMalformed()
+				&& malformAction == CodingErrorAction.REPORT) {
+			throw new MalformedInputException(result.length());
+		} else if (result.isUnmappable()
+				&& unmapAction == CodingErrorAction.REPORT) {
+			throw new UnmappableCharacterException(result.length());
+		}
 		while (flush(output) != CoderResult.UNDERFLOW) {
 			output = allocateMore(output);
 		}

Modified: 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=378491&r1=378490&r2=378491&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetDecoderTest.java
Fri Feb 17 03:53:42 2006
@@ -21,6 +21,7 @@
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CodingErrorAction;
+import java.nio.charset.MalformedInputException;
 
 import junit.framework.TestCase;
 
@@ -49,5 +50,17 @@
 
 		charbuf = Charset.forName("UTF-16LE").decode(buf);
 		assertEquals("Assert 2: charset UTF16LE", 0, charbuf.length());
+		
+		// Regression for HARMONY-99
+		CharsetDecoder decoder2 = Charset.forName("UTF-16").newDecoder();
+		decoder2.onMalformedInput(CodingErrorAction.REPORT);
+		decoder2.onUnmappableCharacter(CodingErrorAction.REPORT);
+		ByteBuffer in = ByteBuffer.wrap(new byte[] { 109, 97, 109 });
+		try {
+			decoder2.decode(in);
+			fail("Assert 3: MalformedInputException should have thrown");
+		} catch (MalformedInputException e) {
+			//expected
+		} 
 	}
 }



Mime
View raw message