Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReflectiveBeanConverter should take MethodHandles.Lookup #3498

Open
agentgt opened this issue Aug 9, 2024 · 3 comments
Open

ReflectiveBeanConverter should take MethodHandles.Lookup #3498

agentgt opened this issue Aug 9, 2024 · 3 comments

Comments

@agentgt
Copy link
Contributor

agentgt commented Aug 9, 2024

Given the discussions on #3496 (and corresponding PR #3494) as well as the new @BindParam I think the reflective bean converter needs some cleanup and possibly should be available as public API.

Some issues:

  • It is bizarre how it does not implement BeanConverter which makes looking for it tricky.
  • Strangely it gets created on every request as a fallback. Maybe escape analysis is working and it is fine performance wise but it makes me wonder if it is threadsafe when I see that.
  • Ideally it uses MethodHandles instead of the older reflection API.

The last point is important in a modular world. There are two choices in allow reflective access if your application is modular. You either

  1. open everything up (as in put open module declaration or package)
  2. or you pass a MethodHandles.Lookup to the library (jooby) doing the reflection.

Thus we should allow one want to do something like (the following may not be correct but roughly):

Jooby app = ...;
var lookup = MethodHandles.lookup(); // the consumer of jooby calls this
app.converter(new ReflectiveBeanConverter(lookup)); // or however we replace the default one.

On a separate note Handlebars.java should do something similar for version 5. In fact you could do

var lookup = MethodHandles.lookup(); // the consumer of jooby calls this
app.registerLookup(lookup); // register lookup to be used by jooby modules.
// jooby handlebars module then does 
var lookup app.getLookup();
Handlebars handlebars = new Handlebars(lookup); // or whatever is analogous

I can try to take a stab at a PR if you like. A bonus to using MethodHandles is that they are supposedly can be faster than regular reflection.

@jknack
Copy link
Member

jknack commented Aug 10, 2024

Make sense, send a PR we can work from there.

@agentgt
Copy link
Contributor Author

agentgt commented Sep 16, 2024

I'll try to get to this before the end of the month. Sorry for the delay.

@agentgt
Copy link
Contributor Author

agentgt commented Sep 19, 2024

Maybe we shoot for 4.0.0 with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants