You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Optional parameters don't work outside of scijava-ops-engine #110
java.lang.IllegalAccessError: class org.scijava.ops.engine.reduce.DefaultMeanFilterReduction1RandomAccessibleInterval_Shape_RandomAccessibleInterval_RandomAccessibleInterval (in module org.scijava.ops.engine) cannot access class net.imagej.ops2.filter.mean.DefaultMeanFilter (in module net.imagej.ops2) because module org.scijava.ops.engine does not read module net.imagej.ops2
at org.scijava.ops.engine@0-SNAPSHOT/org.scijava.ops.engine.reduce.DefaultMeanFilterReduction1RandomAccessibleInterval_Shape_RandomAccessibleInterval_RandomAccessibleInterval.compute(DefaultMeanFilterReduction1RandomAccessibleInterval_Shape_RandomAccessibleInterval_RandomAccessibleInterval.java)
at org.scijava.ops.engine@0-SNAPSHOT/org.scijava.ops.engine.matcher.impl.OpWrappers$Computer2OpWrapper$1GenericTypedComputer2.compute(OpWrappers.java:844)
at org.scijava.ops.api@0-SNAPSHOT/org.scijava.ops.api.OpBuilder$Arity2_IV_OV.compute(OpBuilder.java:1020)
This means that scijava.ops.engine would need a requires xxxx on any package using @Optional in *its own module-info.java, which of course would be cyclic and also non-extensible.
The issue here is that when we are reducing optional parameters, we require the need for an Op of a different functional type. In this example, DefaultMeanFilter should be a Computers.Arity3with the OutOfBoundsFactory, and a Computers.Arity2without the OutOfBoundsFactory. Creating that Computers.Arity2 requires javassist, meaning we can likely fix this using a solution similar to scijava/incubator#69.
Okay, so I have things working on that branch, but I still don't understand why we cannot directly call the functional method of the functional interface. I can do crazy things inside of the javassist reduced Op, like making a new instance of the Op class!
I think we should do more investigation, but I think I've run out of time today to try...
Following JPMS rules of callability I would not expect this class to have access to the underlying op's compute, since it's not in the same package as the original op (net.imagej.ops2.filter.mean) and, as the error message indicates, the module it is in doesn't have read access to ops2.filter.mean.
But, because compute is a method of an interface that is read by the javassist class's module, I don't understand why it doesn't work.
I can do crazy things inside of the javassist reduced Op, like making a new instance of the Op class!
Do you mean via reflection, e.g. Class.newInstance()? Or actually calling new ClassName()? If it's via reflection, that seems to be working as expected since opens..to.. gives reflection access (and thus the solution to use reflection seems reasonable).
things I tried:
exports..to.. doesn't work since it isn't this mysterious "read" access that is only granted by requires
Parameterizing the op with core module classes (FAILED)
Running in python without JPMS (passed!)
Casting the Op to the functional interface that we have access to (FAILED)
Trying to learn more about Javassist and JPMS interactions (Couldn't find anything)
Forcing the Javassist Op to be in the same net.imagej... package as the original op (FAILED)
Some thoughts:
It feels weird to me that our javassist-created Op is a class in an org.scijava package regardless of where it came from...
Is there a way to call the original Op's method without a reference to its class? Can we create a copy of that method inside our new Javassist op itself? and just delegate to ourselves?
The Javassist Op doesn't know any of the generic types of the interface it's implementing, right? Does that affect type safety guarantees of future matches in a given session?
Activity
hinerm commentedon Jan 20, 2023
Branch started: https://github.com/scijava/incubator/tree/imagej/imagej-ops2/optional-params
gselzer commentedon Jan 20, 2023
The issue here is that when we are reducing optional parameters, we require the need for an Op of a different functional type. In this example,
DefaultMeanFiltershould be aComputers.Arity3with theOutOfBoundsFactory, and aComputers.Arity2without theOutOfBoundsFactory. Creating thatComputers.Arity2requires javassist, meaning we can likely fix this using a solution similar to scijava/incubator#69.I'll give it a shot.
gselzer commentedon Jan 20, 2023
Okay, so I have things working on that branch, but I still don't understand why we cannot directly call the functional method of the functional interface. I can do crazy things inside of the javassist reduced Op, like making a new instance of the Op class!
I think we should do more investigation, but I think I've run out of time today to try...
hinerm commentedon Jan 27, 2023
So, ultimately, without this change, the
computemethod is being called in the javassist-created class:Following JPMS rules of callability I would not expect this class to have access to the underlying op's
compute, since it's not in the same package as the original op (net.imagej.ops2.filter.mean) and, as the error message indicates, the module it is in doesn't have read access toops2.filter.mean.But, because
computeis a method of an interface that is read by the javassist class's module, I don't understand why it doesn't work.Do you mean via reflection, e.g.
Class.newInstance()? Or actually callingnew ClassName()? If it's via reflection, that seems to be working as expected sinceopens..to..gives reflection access (and thus the solution to use reflection seems reasonable).things I tried:
exports..to..doesn't work since it isn't this mysterious "read" access that is only granted byrequiresnet.imagej...package as the original op (FAILED)Some thoughts:
org.scijavapackage regardless of where it came from...Make reduction work outside of the engine
Merge pull request #110 from scijava/imagej/purge-folder