Skip to content
This repository was archived by the owner on Oct 26, 2026. It is now read-only.

Handle OpMethods that the SciJava Ops Engine module cannot read - #69

Merged
gselzer merged 4 commits into
mainfrom
scijava/scijava-ops-engine/non-readable-op-methods
Jan 13, 2023
Merged

gselzer merged 4 commits into
mainfrom
scijava/scijava-ops-engine/non-readable-op-methods

Conversation

@gselzer

@gselzer gselzer commented Jan 12, 2023 •

Copy link
Copy Markdown
Member

SciJava Ops Engine employs two different pathways for turning public static Methods into Ops. Both of these pathways try to obtain the Method by loading the owning Class, which fails when the org.scijava.ops.engine module does not require the module containing the Method. This is the case for ImageJ Ops2, and for all Op-containing modules we'd like to create in the future. This escaped our attention because we hadn't actually created any OpMethods in ImageJ Ops2 🤦

Well, fortunately for us, we don't need to import the Class, because Discovery will always give us an instance of that Method anyways, and we don't need an owner instance because OpMethods must be static. For that reason, we can modify our javassist pathway to call Method.invoke on the Method instance we already have.

Points of discussion:

  • What do we want to do with the other pathway, which will no longer work (unless the engine requires its module, which is only the case for the engine itself right now). Should we get rid of it? Should we add a Module access check to the conditional?
  • How do we want to test that this is fixed? We would have to change an Op outside of the engine to test this....

TODO:

  • Test this...somehow
  • Clean up the Javassist code

@gselzer gselzer added the bug Something isn't working label Jan 12, 2023
@gselzer
gselzer requested a review from hinerm January 12, 2023 21:55
@gselzer gselzer self-assigned this Jan 12, 2023
@gselzer
gselzer force-pushed the scijava/scijava-ops-engine/non-readable-op-methods branch from bfc83a5 to ce1fefb Compare January 12, 2023 22:47
@hinerm

hinerm commented Jan 13, 2023

Copy link
Copy Markdown
Member

Test this...somehow

@gselzer do you need to more than just a simple test Op declared in ImageJ-ops2 that hits this path?

@gselzer

gselzer commented Jan 13, 2023

Copy link
Copy Markdown
Member Author

Test this...somehow

@gselzer do you need to more than just a simple test Op declared in ImageJ-ops2 that hits this path?

I mean, we can do that, it's just an indirect test. And we'd want to find an Op where it doesn't look weird, i.e. it would look weird to make only one OpField of an OpCollection into an OpMethod...

I was hoping I could make these methods, but it's just too simple to
require a method...
This makes an implicit test for OpMethods in non-readable modules
@gselzer

gselzer commented Jan 13, 2023

Copy link
Copy Markdown
Member Author

@hinerm alright, I rewrote the filter.gauss Ops as methods, so we have an implicit test.

One thing that tripped me up during this rewrite is that I mistakenly used a double in one of the methods, instead of the object Double. I'm guessing that this is something others will be tripped up on when writing OpMethods, because unlike with classes and fields where you have to write a generic type the OpMethod won't throw a compile error if you use a primitive.

I'm going to create an issue to see if we can get around this by boxing any primitives in OpMethods. This would also be a useful feature when wrapping existing methods that take primitive parameters.

@gselzer
gselzer marked this pull request as ready for review January 13, 2023 19:20
@gselzer

gselzer commented Jan 13, 2023

Copy link
Copy Markdown
Member Author

What do we want to do with the other pathway, which will no longer work (unless the engine requires its module, which is only the case for the engine itself right now). Should we get rid of it? Should we add a Module access check to the conditional?

My solution, for now, is to let it remain, but to guard behind a module visibility check (see 8788ba9)

@gselzer
gselzer merged commit 7d70b7d into main Jan 13, 2023
@gselzer
gselzer deleted the scijava/scijava-ops-engine/non-readable-op-methods branch January 13, 2023 19:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants