[java] actually iterate over opendir until it's closed - related to #2916