{"record":{"id":"ddf624cb185a0f9d","repo":"quarkusio/quarkus","slug":"paths-collection-expected-to-contain-a-single-path","errorCode":null,"errorMessage":"Paths collection expected to contain a single path but contains ","messagePattern":"Paths collection expected to contain a single path but contains ","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"independent-projects/bootstrap/app-model/src/main/java/io/quarkus/paths/PathCollection.java","lineNumber":18,"sourceCode":"package io.quarkus.paths;\n\nimport java.nio.file.Path;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.stream.Stream;\n\npublic interface PathCollection extends Iterable<Path> {\n\n    boolean isEmpty();\n\n    int size();\n\n    boolean isSinglePath();\n\n    default Path getSinglePath() {\n        if (size() != 1) {\n            throw new IllegalStateException(\"Paths collection expected to contain a single path but contains \" + size());\n        }\n        return iterator().next();\n    }\n\n    boolean contains(Path path);\n\n    PathCollection add(Path... paths);\n\n    PathCollection addFirst(Path... paths);\n\n    PathCollection addAllFirst(Iterable<Path> i);\n\n    Path resolveExistingOrNull(String path);\n\n    default Stream<Path> stream() {\n        final List<Path> list = new ArrayList<>(size());\n        for (Path p : this) {\n            list.add(p);","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/paths/PathCollection.java#L1-L36","documentation":"PathCollection.getSinglePath() is a convenience for collections known to hold exactly one path. It throws IllegalStateException when the collection has any size other than 1. The message reports the actual size, e.g. '...but contains 3'.","triggerScenarios":"Calling getSinglePath() on a PathCollection whose size() != 1 — e.g. a multi-release or classpath element that resolved to 0 paths (missing artifact) or multiple paths (several classpath entries / duplicate locations).","commonSituations":"Calling it on getClassPaths()/application roots during Quarkus dev mode where multiple class directories exist; calling it on an empty collection after a dependency was excluded; assuming a single-location deployment when running in dev or test mode.","solutions":["Check isSinglePath() before calling getSinglePath().","Handle the multi-path case by iterating the collection instead of taking one element.","If you expected exactly one path, fix the environment (remove duplicate classpath entries / restore the missing dependency).","Catch IllegalStateException and fall back to iteration if multiple paths are acceptable."],"exampleFix":"// before\nPath single = pathCollection.getSinglePath(); // IllegalStateException when size != 1\n// after\nPath single = pathCollection.isSinglePath()\n        ? pathCollection.getSinglePath()\n        : pathCollection.iterator().next();","handlingStrategy":"type-guard","validationCode":"if (pathCollection == null || pathCollection.size() != 1) {\n    throw new IllegalStateException(\"Expected exactly one path, got \" + (pathCollection == null ? \"null\" : pathCollection.size()));\n}","typeGuard":"static boolean hasSinglePath(PathCollection c) {\n    return c != null && c.isSinglePath();\n}","tryCatchPattern":"try {\n    Path single = pathCollection.getSinglePath();\n} catch (IllegalStateException e) {\n    Path first = pathCollection.iterator().hasNext() ? pathCollection.iterator().next() : null;\n    // fall back to first element or handle empty\n}","preventionTips":["Always check isSinglePath() before getSinglePath().","Remember dev mode often yields multiple classpath roots — don't assume one.","Log the full collection when size != 1 to diagnose duplicates/emptiness.","Handle empty collections explicitly; size()==0 also throws."],"tags":["illegal-state","collections","quarkus-paths","classpath"],"backgroundTag":"unexpected-collection-size","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}