more correct version of fix for possible infinite loop on java import