I don't think these two parts of the documentation contradict each other.
When you get to the end of your input data, you should call engine.closeInbound()
This applies to both cleanly closed and severed connections. It's when the connection has been severed that the exception will be thrown (i.e. if you call it before having received close_notify
).
If close_notify
was received (or if the connection hasn't even started at all), this exception won't be thrown.
I'm not quite sure how you've made your simple shutdown test, but you should have sent close_notify
from the other end first (with closeOutbound()
, for example). In this case, you shouldn't have received -1 from socketChannel.read()
before getting close_notify
(and you wouldn't get an exception then).
(Just in case that's of interest, there was a similar question on SSLSocket
a while ago.)