Correcting java bug