Skip to content

Commit 5ec415e

Browse files
committed
Throw IAE when no discoverable functional method
Null returns can be misleading, and could give the impression that this is a side-effects-based Op (such as a Consumers.Arity0).
1 parent b821e78 commit 5ec415e

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

scijava/scijava-ops/src/main/java/org/scijava/param/ParameterStructs.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ public static List<Member<?>> parse(final OpInfo opInfo, final List<Simplifier<?
340340
*/
341341
public static List<FunctionalMethodType> findFunctionalMethodTypes(Type functionalType) {
342342
Method functionalMethod = findFunctionalMethod(Types.raw(functionalType));
343-
if (functionalMethod == null) return null;
343+
if (functionalMethod == null) throw new IllegalArgumentException("Type " +
344+
functionalType +
345+
" is not a functional type, thus its functional method types cannot be determined");
344346

345347
Type paramfunctionalType = functionalType;
346348
if (functionalType instanceof Class) {
@@ -491,9 +493,13 @@ private static Parameter[] synthesizeParameterAnnotations(final List<FunctionalM
491493
private static void parseFunctionalParameters(final ArrayList<Member<?>> items, final Set<String> names, final ArrayList<ValidityProblem> problems,
492494
AnnotatedElement annotationBearer, Type type, final boolean synthesizeAnnotations) {
493495
//Search for the functional method of 'type' and map its signature to ItemIO
494-
List<FunctionalMethodType> fmts = findFunctionalMethodTypes(type);
495-
if (fmts == null) {
496-
problems.add(new ValidityProblem("Could not find functional method of " + type.getTypeName()));
496+
List<FunctionalMethodType> fmts;
497+
try {
498+
fmts = findFunctionalMethodTypes(type);
499+
}
500+
catch (IllegalArgumentException e) {
501+
problems.add(new ValidityProblem("Could not find functional method of " +
502+
type.getTypeName()));
497503
return;
498504
}
499505

0 commit comments

Comments
 (0)