jira-importer opened a new issue, #809: URL: https://github.com/apache/httpcomponents-core/issues/809
**[Bill Speirs](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=wspeirs)** opened **[HTTPCORE-270](https://issues.apache.org/jira/browse/HTTPCORE-270?redirect=false)** and commented I am using httpclient-4.1.2 & httpcore-4.2-alpha1. In making an DefaultHttpClient.execute() call I get the following exception: java.lang.IllegalStateException: Current state = RESET, new state = FLUSHED at java.nio.charset.CharsetEncoder.throwIllegalStateException(CharsetEncoder.java:951) at java.nio.charset.CharsetEncoder.flush(CharsetEncoder.java:640) at org.apache.http.impl.io.AbstractSessionOutputBuffer.writeEncoded(AbstractSessionOutputBuffer.java:264) at org.apache.http.impl.io.AbstractSessionOutputBuffer.writeLine(AbstractSessionOutputBuffer.java:247) at org.apache.http.impl.conn.LoggingSessionOutputBuffer.writeLine(LoggingSessionOutputBuffer.java:99) at org.apache.http.impl.io.AbstractMessageWriter.write(AbstractMessageWriter.java:97) at org.apache.http.impl.AbstractHttpClientConnection.sendRequestHeader(AbstractHttpClientConnection.java:253) On line 264 of AbstractSessionOutputBuffer.java, encoder.flush() is being called. My thought (I have not completely debugged) is that in this instance, cbuf.hasRemaining() is false, and therefor the following calls are being made: encoder.reset() encoder.flush() This is resulting in the above exception. I believe the following small patch will short-circuit the code, and fix the issue. Thoughts? Index: httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java --- --- httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java (revision 1160689) +++ httpcore/src/main/java/org/apache/http/impl/io/AbstractSessionOutputBuffer.java (working copy) @@ -256,6 +256,10 @@ if (this.bbuf == null) { this.bbuf = ByteBuffer.allocate(1024); } + if(!cbuf.hasRemaining()) { + return; + } + this.encoder.reset(); while (cbuf.hasRemaining()) { CoderResult result = this.encoder.encode(cbuf, this.bbuf, true); --- **Affects:** 4.2-alpha1 **Attachments:** - [SocketOutputBuffer.diff](https://issues.apache.org/jira/secure/attachment/12491381/SocketOutputBuffer.diff) (_5.99 kB_) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
