Unit test and proposed solution for issue #2312

This pull request re-creates issue #2312 and provides a proposed solution. It actually matches the logic used one method down in `internalNioBuffer`.