Skip to content

Commit 1146536

Browse files
gselzerctrueden
authored andcommitted
Allow private Ops (test-specific Ops, etc)
1 parent 6b91cde commit 1146536

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/main/java/org/scijava/ops/matcher/OpClassInfo.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
package org.scijava.ops.matcher;
3131

32+
import java.lang.reflect.Constructor;
33+
import java.lang.reflect.InvocationTargetException;
3234
import java.lang.reflect.Type;
3335
import java.util.List;
3436

@@ -106,12 +108,14 @@ public StructInstance<?> createOpInstance() {
106108
// TODO: Consider whether this is really the best way to
107109
// instantiate the op class here. No framework usage?
108110
// E.g., what about pluginService.createInstance?
109-
object = opClass.newInstance();
110-
} catch (final InstantiationException | IllegalAccessException e) {
111+
Constructor<? extends Op> ctor = opClass.getDeclaredConstructor();
112+
ctor.setAccessible(true);
113+
object = ctor.newInstance();
114+
} catch (final InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException e) {
111115
// TODO: Think about whether exception handling here should be
112116
// different.
113117
throw new IllegalStateException("Unable to instantiate op: '" + opClass.getName()
114-
+ "' Each op must have a no-args constructor.", e);
118+
+ "' Ensure that the Op has a no-args constructor.", e);
115119
}
116120
return struct().createInstance(object);
117121
}

0 commit comments

Comments
 (0)