Simplify HashSet usage for computed Classpaths

Since the LinkedHashSet prevents duplicates, processing classpaths in
topological order produces the same output, but would make the code more
complicated.

Fixes #1002311
Add cycle detection to classpath computation.

Fixes #1002179.