harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r409162 - in /incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src: main/java/java/nio/charset/CharsetEncoder.java test/java/org/apache/harmony/tests/java/nio/charset/CharsetEncoderTest.java
Date Wed, 24 May 2006 13:53:24 GMT
Author: mloenko
Date: Wed May 24 06:53:23 2006
New Revision: 409162

URL: http://svn.apache.org/viewvc?rev=409162&view=rev
Log:
fixes and regression test for HARMONY-491
[classlib] Constructors of java.nio.charset.CharsetEncoder should not throw NPE if charset==null

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetEncoderTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java?rev=409162&r1=409161&r2=409162&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/java/nio/charset/CharsetEncoder.java
Wed May 24 06:53:23 2006
@@ -202,7 +202,6 @@
 		status = INIT;
 		malformAction = CodingErrorAction.REPORT;
 		unmapAction = CodingErrorAction.REPORT;
-		decoder = cs.newDecoder();
 		replaceWith(replacement);
 	}
 
@@ -722,18 +721,22 @@
 	 *         replacement byte array.
 	 */
 	public boolean isLegalReplacement(byte[] repl) {
-		CodingErrorAction malform = decoder.malformedInputAction();
-		CodingErrorAction unmap = decoder.unmappableCharacterAction();
-		decoder.onMalformedInput(CodingErrorAction.REPORT);
-		decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
-		ByteBuffer in = ByteBuffer.wrap(repl);
-		CharBuffer out = CharBuffer.allocate((int) (repl.length * decoder
-				.maxCharsPerByte()));
-		CoderResult result = decoder.decode(in, out, true);
-		decoder.onMalformedInput(malform);
-		decoder.onUnmappableCharacter(unmap);
-		return !result.isError();
-	}
+        if (decoder == null) {
+            decoder = cs.newDecoder();
+        }
+
+        CodingErrorAction malform = decoder.malformedInputAction();
+        CodingErrorAction unmap = decoder.unmappableCharacterAction();
+        decoder.onMalformedInput(CodingErrorAction.REPORT);
+        decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+        ByteBuffer in = ByteBuffer.wrap(repl);
+        CharBuffer out = CharBuffer.allocate((int) (repl.length * decoder
+                .maxCharsPerByte()));
+        CoderResult result = decoder.decode(in, out, true);
+        decoder.onMalformedInput(malform);
+        decoder.onUnmappableCharacter(unmap);
+        return !result.isError();
+    }
 
 	/**
 	 * Gets this encoder's <code>CodingErrorAction</code> when malformed input

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetEncoderTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetEncoderTest.java?rev=409162&r1=409161&r2=409162&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetEncoderTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio_char/src/test/java/org/apache/harmony/tests/java/nio/charset/CharsetEncoderTest.java
Wed May 24 06:53:23 2006
@@ -52,10 +52,21 @@
 		}
 	}
 
-	/**
-	 * Helper for contructor tests
-	 */
-	public static class MockCharsetEncoderForHarmony141 extends CharsetEncoder {
+    /**
+     * @tests java.nio.charset.CharsetEncoder.CharsetEncoder(
+     *        java.nio.charset.Charset, float, float)
+     */
+    public void test_ConstructorLjava_nio_charset_CharsetNull() {
+        // Regression for HARMONY-491
+        CharsetEncoder ech = new MockCharsetEncoderForHarmony491(null, 1, 1);
+        assertNull(ech.charset());
+    }
+
+    /**
+     * Helper for contructor tests
+     */
+
+    public static class MockCharsetEncoderForHarmony141 extends CharsetEncoder {
 
 		protected MockCharsetEncoderForHarmony141(Charset cs,
 				float averageBytesPerChar, float maxBytesPerChar) {
@@ -73,9 +84,25 @@
 		}
 	}
 
-	/*
-	 * Test malfunction encode(CharBuffer)
-	 */
+    public static class MockCharsetEncoderForHarmony491 extends CharsetEncoder {
+
+        public MockCharsetEncoderForHarmony491(Charset arg0, float arg1,
+                float arg2) {
+            super(arg0, arg1, arg2);
+        }
+
+        protected CoderResult encodeLoop(CharBuffer arg0, ByteBuffer arg1) {
+            return null;
+        }
+
+        public boolean isLegalReplacement(byte[] arg0) {
+            return true;
+        }
+    }
+
+    /*
+     * Test malfunction encode(CharBuffer)
+     */
 	public void test_EncodeLjava_nio_CharBuffer() throws Exception {
 		MockMalfunctionCharset cs = new MockMalfunctionCharset("mock", null);
 		try {



Mime
View raw message