You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ml...@apache.org on 2006/05/24 15:53:24 UTC
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
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 {