Skip to content

Commit 39d62a3

Browse files
gselzerctrueden
authored andcommitted
Prevent NSEExceptions when OpMethod type incorrect
Suppose that an Inplace OpMethod is annotated with the functional interface BiFunction. We must catch these situations quickly and fail before the struct is generated, as it is not the job of ParameterStructs to deal with incorrectly annotated methods
1 parent ede9d55 commit 39d62a3

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

scijava/scijava-ops/src/main/java/org/scijava/ops/matcher/OpMethodInfo.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,15 @@ public OpMethodInfo(final Method method) {
9797
}
9898
this.method = method;
9999
this.hints = formHints(method.getAnnotation(OpHints.class));
100+
// determine the functional interface this Op should implement
101+
final OpMethod methodAnnotation = method.getAnnotation(OpMethod.class);
100102
try {
103+
opType = ParameterStructs.getOpMethodType(methodAnnotation.type(),
104+
method);
101105
struct = ParameterStructs.structOf(method.getDeclaringClass(), method);
102-
final OpMethod methodAnnotation = method.getAnnotation(OpMethod.class);
103-
try {
104-
opType = ParameterStructs.getOpMethodType(methodAnnotation.type(),
105-
method);
106-
}
107-
catch (IllegalArgumentException e) {
108-
opType = Types.parameterizeRaw(methodAnnotation.type());
109-
}
106+
}
107+
catch (IllegalArgumentException e) {
108+
problems.add(new ValidityProblem(e));
110109
}
111110
catch (final ValidityException e) {
112111
problems.addAll(e.problems());

scijava/scijava-ops/src/test/java/org/scijava/param/JavadocParameterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import org.junit.Assert;
1515
import org.junit.Test;
16+
import org.scijava.function.Computers;
1617
import org.scijava.ops.AbstractTestEnvironment;
1718
import org.scijava.ops.OpField;
1819
import org.scijava.ops.OpInfo;

0 commit comments

Comments
 (0)