Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

EventListener registration does not work with package private annotated types #1089

Closed
odrotbohm opened this issue Sep 27, 2021 · 2 comments
Closed
Assignees
Labels
type: bug A general bug
Milestone

Comments

@odrotbohm
Copy link

odrotbohm commented Sep 27, 2021

Steps to reproduce

$ git clone https://github.com/odrotbohm/spring-restbucks
$ cd spring-restbucks
$ git checkout hacking/aot
$ ./mvnw verify -DskipTests

Outcome

Compilation fails due to references to package protected classes from target/generated-sources/spring-aot/src/main/java/org/springframework/aot/ContextBootstrapInitializer.java:

context.registerBean("org.springframework.aot.EventListenerRegistrar", EventListenerRegistrar.class, () -> new EventListenerRegistrar(context,
  EventListenerMetadata.forBean("engine", Engine.class).eventListenerFactoryBeanName("org.springframework.transaction.config.internalTransactionalEventListenerFactory").annotatedMethod("handleOrderPaidEvent", OrderPaid.class),
  EventListenerMetadata.forBean("orderInitializer", OrderInitializer.class).annotatedMethod("init", ApplicationReadyEvent.class)
));

The references to Engine and OrderInitializer cause the compile errors, as they're package protected. Making them public as a workaround works.

Expected outcome

The generated code compiles successfully.

Other observations

I see the actual instance creation code generated into the application package for the package protected classes, too. So it seems that it's the event listener related, generated code that does not yet honor the package protection.

@snicoll
Copy link
Contributor

snicoll commented Sep 27, 2021

Event listener registration doesn't support package private event listeners indeed. This is something that was on my TODO list. Thanks for raising the issue.

@snicoll snicoll added type: bug A general bug theme: aot labels Sep 27, 2021
@snicoll snicoll added this to the 0.11.x milestone Sep 27, 2021
@snicoll snicoll changed the title AOT code generation generates code that tries to refer to package protected code from a framework package EventListener registration does not work with package private annotated types Sep 28, 2021
@snicoll snicoll self-assigned this Sep 28, 2021
@snicoll snicoll modified the milestones: 0.11.x, 0.11.0-M1 Sep 28, 2021
@snicoll
Copy link
Contributor

snicoll commented Sep 28, 2021

Moving to M1 to give restbucks a chance to work sooner than later.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A general bug
Development

No branches or pull requests

2 participants