Misc fixes and improvements

Hi,

got a few fixes which have been running in production (on top of f254c479d6b1dd55cfa40a85b19fbba95348553d / 0.6.45) since december;
one generic fix, and a few Java-compat improvements (such as capabilities support). Please see the commits for details.

Thanks!