Fixes to java_gen

Reviewer: @vaterlaus @yotamhc