{"record":{"id":"3b3812b0f908f9eb","repo":"junit-team/junit5","slug":"emptysource-cannot-provide-an-empty-argument-s","errorCode":null,"errorMessage":"@EmptySource cannot provide an empty argument %s: [%s] is not a supported type.","messagePattern":"@EmptySource cannot provide an empty argument (.+?): \\[(.+?)\\] is not a supported type\\.","errorType":"exception","errorClass":"PreconditionViolationException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/EmptyArgumentsProvider.java","lineNumber":117,"sourceCode":"\t\t}\n\t\tif (SortedMap.class.equals(parameterType)) {\n\t\t\treturn Stream.of(arguments(Collections.emptySortedMap()));\n\t\t}\n\t\tif (NavigableMap.class.equals(parameterType)) {\n\t\t\treturn Stream.of(arguments(Collections.emptyNavigableMap()));\n\t\t}\n\t\tif (Collection.class.isAssignableFrom(parameterType) || Map.class.isAssignableFrom(parameterType)) {\n\t\t\tOptional<Constructor<?>> defaultConstructor = getDefaultConstructor(parameterType);\n\t\t\tif (defaultConstructor.isPresent()) {\n\t\t\t\treturn Stream.of(arguments(newInstance(defaultConstructor.get())));\n\t\t\t}\n\t\t}\n\t\tif (parameterType.isArray()) {\n\t\t\tObject array = Array.newInstance(parameterType.getComponentType(), 0);\n\t\t\treturn Stream.of(arguments(array));\n\t\t}\n\t\t// else\n\t\tthrow new PreconditionViolationException(\n\t\t\t\"@EmptySource cannot provide an empty argument %s: [%s] is not a supported type.\".formatted(\n\t\t\t\terrorDetailsSupplier.get(), parameterType.getName()));\n\t}\n\n\tprivate static Optional<Constructor<?>> getDefaultConstructor(Class<?> clazz) {\n\t\ttry {\n\t\t\treturn Optional.of(clazz.getConstructor());\n\t\t}\n\t\tcatch (NoSuchMethodException e) {\n\t\t\treturn Optional.empty();\n\t\t}\n\t}\n\n\t/**\n\t * @since 6.1\n\t */\n\tprivate static class EmptyIterable<E> implements Iterable<E> {\n","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/provider/EmptyArgumentsProvider.java#L99-L135","documentation":"Thrown by EmptyArgumentsProvider when @EmptySource is applied to a parameter whose type is not supported for empty provisioning: it handles Collection/Map with a default constructor, arrays, and a few specific types above; anything else falls through to the final PreconditionViolationException. The message names the unsupported type and error details.","triggerScenarios":"Annotating a @ParameterizedTest parameter of an unsupported type (e.g. a custom POJO, an int primitive, a type with no default constructor that is not an array/String/etc.) with @EmptySource. The provider exhausts its type checks and reaches the else branch.","commonSituations":"Applying @EmptySource to a parameter whose type is neither a Collection, Map, array, String, nor other built-in empty-supported type. Using @EmptySource together with a custom type expecting the framework to figure out emptiness.","solutions":["Change the parameter type to one @EmptySource supports (String, List, Set, Map, array, Optional, etc.).","For custom types, supply empty values explicitly via @NullSource/@ValueSource/@MethodSource instead of @EmptySource.","Remove @EmptySource from parameters of unsupported types."],"exampleFix":"// before\n@ParameterizedTest\n@EmptySource\nvoid test(MyPojo p) { }\n\n// after\n@ParameterizedTest\n@NullAndEmptySource\nvoid test(List<?> items) { }","handlingStrategy":"validation","validationCode":"// Check that @EmptySource is only applied to supported types\nSet<Class<?>> supported = Set.of(String.class, List.class, ArrayList.class, Set.class, HashSet.class, Map.class, HashMap.class);\nif (!supported.contains(parameterType) && !parameterType.isArray())\n    throw new IllegalArgumentException(\"@EmptySource not supported for \" + parameterType);","typeGuard":"static boolean supportsEmptySource(Class<?> t) {\n    return t == String.class || Collection.class.isAssignableFrom(t) || Map.class.isAssignableFrom(t) || t.isArray();\n}","tryCatchPattern":null,"preventionTips":["Restrict @EmptySource to collection, map, array, or String parameters.","For custom types, supply empty values via @MethodSource or @ValueSource.","Review parameter types before adding @EmptySource."],"tags":["junit-jupiter","parameterized-test","empty-source","type-mismatch"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}