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

AutoProvideAspects doesn't work as expected #269

Closed
SentryMan opened this issue Jan 31, 2023 · 0 comments · Fixed by #271
Closed

AutoProvideAspects doesn't work as expected #269

SentryMan opened this issue Jan 31, 2023 · 0 comments · Fixed by #271
Assignees
Milestone

Comments

@SentryMan
Copy link
Collaborator

SentryMan commented Jan 31, 2023

Say I got this aspect @Timed in module A (with a target of TimedAspect.class), and I try to use @Timed on a method in module B. The generated proxy class in module b is:

@Proxy
@Generated("io.avaje.inject.generator")
public final class ServiceClass$Proxy extends ServiceClass {

  private Method callDownStream0;
  private MethodInterceptor callDownStream0Timed;

  public ServiceClass$Proxy(AspectProvider<Timed> timed, ApiClient api) {
    super(api);
    try {
      callDownStream0 = ServiceClass.class.getDeclaredMethod("callDownStream");
      callDownStream0Timed = timed.interceptor(callDownStream0, callDownStream0.getAnnotation(Timed.class));
    } catch (Exception e) {
      throw new IllegalStateException(e);
    }
  }

  @Override
  public byte[] callDownStream() {
    var call = new Invocation.Call<>(() -> super.callDownStream())
      .with(this, callDownStream0);
    try {
      callDownStream0Timed.invoke(call);
      return call.finalResult();
    } catch (InvocationException e) {
      throw e;
    } catch (Throwable e) {
      throw new InvocationException(e);
    }
  }
}

Currently, module b fails to compile with

No dependency provided for io.avaje.inject.aop.AspectProvider<com.jojo.javalin.api.aspect.Timed> on 
com.jojo.javalin.shade.service.ServiceClass$Proxy

Currently the only way to get an annotation from module A to work with module B, is to add an explicit @InjectModules(provides=TimedAspect.class) to module A.

One would expect that auto provide aspects would eliminate the need for explicit @InjectModules provides.

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

Successfully merging a pull request may close this issue.

2 participants