@@ -203,31 +203,36 @@ public StructInstance<?> createOpInstance(
203203 {
204204
205205 // Case 1: no dependencies - lambdaMetaFactory is fastest
206- // if (dependencies().size() == 0) {
207- // try {
208- // method.setAccessible(true);
209- // MethodHandle handle = MethodHandles.lookup().unreflect(method);
210- // Object op = Adapt.Methods.lambdaize(Types.raw(opType), handle);
211- // return struct().createInstance(op);
212- // }
213- // catch (Throwable exc) {
214- // throw new IllegalStateException("Failed to invoke Op method: " + method,
215- // exc);
216- // }
217- // }
206+ // NB LambdaMetaFactory only works if this Module (org.scijava.ops.engine)
207+ // can read the Module containing the Op. So we also have to check that.
208+ Module methodModule = method .getDeclaringClass ().getModule ();
209+ Module opsEngine = this .getClass ().getModule ();
210+
211+ if (opsEngine .canRead (methodModule ) && dependencies .isEmpty ()) {
212+ try {
213+ method .setAccessible (true );
214+ MethodHandle handle = MethodHandles .lookup ().unreflect (method );
215+ Object op = Adapt .Methods .lambdaize (Types .raw (opType ), handle );
216+ return struct ().createInstance (op );
217+ }
218+ catch (Throwable exc ) {
219+ throw new IllegalStateException ("Failed to invoke Op method: " + method ,
220+ exc );
221+ }
222+ }
218223
219224 // Case 2: dependenies - Javassist is best
220225 try {
221226 return struct ().createInstance (javassistOp (method , dependencies ));
222227 }
223228 catch (Throwable ex ) {
224229 throw new IllegalStateException ("Failed to invoke Op method: " + method +
225- ". Provided Op dependencies were: " + Objects . toString ( dependencies ) ,
230+ ". Provided Op dependencies were: " + dependencies ,
226231 ex );
227232 }
228233
229234 }
230-
235+
231236 /**
232237 * Creates a class that knows how to create a partial application of an Op,
233238 * and returns that partial application. Specifically, the class knows how to
0 commit comments