Fixing odd java array length behaviour