Fix AIOOBE.
Fix NPE when pasting an empty buffer

Right-click paste is grayed out when buffer is empty, but middle button
paste is still available
Merge remote-tracking branch 'upstream/master'