Skip to content

Commit

Permalink
More helpful error message for ExtensionList.lookupSingleton (#8646)
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Oct 30, 2023
1 parent 6b0fab1 commit 36de7a5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/src/main/java/hudson/ExtensionList.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,10 @@ public static <T> ExtensionList<T> create(Jenkins jenkins, Class<T> type) {
*/
public static @NonNull <U> U lookupSingleton(Class<U> type) {
ExtensionList<U> all = lookup(type);
if (all.size() != 1) {
if (Main.isUnitTest && all.isEmpty()) {
throw new IllegalStateException("Found no instances of " + type.getName() +
" registered (possible annotation processor issue); try using `mvn clean test -Dtest=…` rather than an IDE test runner");
} else if (all.size() != 1) {
throw new IllegalStateException("Expected 1 instance of " + type.getName() + " but got " + all.size());
}
return all.get(0);
Expand Down

0 comments on commit 36de7a5

Please sign in to comment.