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.
Add cycle detection to classpath computation.

Fixes #1002179.