I've solved a bug 'org.apache.mina.filter.codec. ProtocolDecoderException: java. nio.charset.MalformedInput Exception: Input length = 1 (Hexdump: AC ... 94)'

error=

/org.apache.mina.filter.codec.ProtocolDecoderException: java.nio.charset.MalformedInputException: Input length = 1 (Hexdump: AC … 94)

// at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecF ilter.java:170)

// at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(Ab stractIoFilterChain.java:299)

// at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilt erChain.java:53)

// at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceive d(AbstractIoFilterChain.java:648)

// at org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorFilter.java :239)

// at org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.run(Execut orFilter.java:283)

// at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java: 886)

// at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

// at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)

// at java.lang.Thread.run(Thread.java:662)

//Caused by: java.nio.charset.MalformedInputException: Input length = 1

// at java.nio.charset.CoderResult.throwException(CoderResult.java:260)

// at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:781)

// at org.jivesoftware.openfire.nio.XMLLightweightParser.read(XMLLightweightParser.ja va:183)

// at org.jivesoftware.openfire.nio.XMPPDecoder.doDecode(XMPPDecoder.java:45)

// at org.apache.mina.filter.codec.CumulativeProtocolDecoder.decode(CumulativeProtoco lDecoder.java:133)

// at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecF ilter.java:163)

// … 9 more

error source=org.jivesoftware.openfire.nio.XMPPDecoder

3.7 original code

// Parse as many stanzas as possible from the received data

parser.read(in);

patched code

// Parse as many stanzas as possible from the received data

int pos=in.position();//Returns this buffer’s position

try {

parser.read(in);

} catch (java.nio.charset.MalformedInputException e) {

in.position(pos);//Sets this buffer’s position.

return false;// Return false if remaining data is not enough to decode, then this method will be invoked again when more data is cumulated.

}

Thanks, filed OF-449

Exactly when is this a problem? Please provide a test case that exposes any problem.

The #read() method of the parser already checks for double-byte characters. That is supposed to fix issues that appear to be fixed by the proposed patch. The proposed patch does hide a great deal of Exceptions, in the assumption that this will always be caused by having not enough data to decode. I’m reluctant to apply it because of that.

See my explain http://community.igniterealtime.org/message/212113#212113

you only checks for double-byte characters, but utf8’s character may be 1-6bytes , most Chinese/Japan/Korea character is 3 bytes