backport fixes to build on Java 7