Tested with other conditions mentioned elsewhere: "/usr/java/jdk1.8/bin" "/usr/java/jdk/bin" "/usr/java/jdk1.8-beta/bin" and I get the "/usr/java/jdk-13/bin" as asked by the problem What am I missing? (I removed some out of bounds checks from the code just to simplify things on read).