It fails with Weld 3.0.0, 3.0.1, and 3.0.2. I'll try again with Weld 2.x as I don't remember exactly which version I used previously.
The environment is Java SE + Jersey + Grizzly. The class with the private observer is application scoped.
According to my logs, the following sequence occurs: - First, an application scoped class has an observer to observe the application scoped context initialization event: {code:java} @Observes @Initialized(ApplicationScoped.class) {code} - This observer is also an intercepted method; it's private and it's successfully invoked. - During the execution of this observer, an event is fired. - This event triggers the instantiation of another application scoped class, which has a private observer for this event. - An exception occurs when trying to invoke this private observer.
Code sample - first class:
{code:java} @Inject @DomainLayer private Event<PreparationUpdate> eventService;
/** * The function to invoke when the service is started. * * @param any not used. */ @Scheduled(transactional = true) private void onStartup(@Observes @Initialized(ApplicationScoped.class) Object any) { if (!repo.head().isPresent()) { int numberOfJobs = 500; populate(numberOfJobs); }
PreparationAreaPopulated update = new PreparationAreaPopulated(repo.entries().mapToLong(PreparationEntry::jobId)); eventService.fire(update); } {code}
Second class:
{code:java}
/** * Observes the preparation area enumerated events. * * @param event an observed event. */ private void onEvent(@Observes @DomainLayer PreparationAreaPopulated event) { LOGGER.info("contents of preparation area enumerated"); jobIdList.clear(); event.jobIds().forEach(jobIdList::add); }
{code}
The observer of the second class is not invoked if private. The stack trace is:
{code:java} Exception in thread "main" javax.enterprise.event.ObserverException at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488) at java.base/java.lang.Class.newInstance(Class.java:558) at org.jboss.weld.security.NewInstanceAction.run(NewInstanceAction.java:33) at java.base/java.security.AccessController.doPrivileged(Native Method) at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:40) at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:78) at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:103) at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:85) at org.jboss.weld.injection.MethodInvocationStrategy$SimpleMethodInvocationStrategy.invoke(MethodInvocationStrategy.java:129) at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:330) at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:308) at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:286) at javax.enterprise.inject.spi.ObserverMethod.notify(ObserverMethod.java:124) at org.jboss.weld.util.Observers.notify(Observers.java:166) at org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:285) at org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:273) at org.jboss.weld.event.EventImpl.fire(EventImpl.java:96) at steappe.preparation.infra.PreparationApplicationService.onStartup(PreparationApplicationService.java:221) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.jboss.weld.interceptor.proxy.TerminalAroundInvokeInvocationContext.proceedInternal(TerminalAroundInvokeInvocationContext.java:51) at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:78) at steappe.micro.chassis.infra.interceptors.AbstractScheduledMethodInterceptor.proceed(AbstractScheduledMethodInterceptor.java:22) at steappe.micro.chassis.infra.interceptors.ScheduledTransactionalMethodInterceptor.doIntercept(ScheduledTransactionalMethodInterceptor.java:81) at steappe.micro.chassis.infra.interceptors.ScheduledTransactionalMethodInterceptor.lambda$intercept$0(ScheduledTransactionalMethodInterceptor.java:50)
{code}
A third class, also application scoped, has a private observer of the same event, and this observer is correctly invoked (once I change the access of the observer of the second class to package-private). Then both observers are invoked, one is package-private, and the other one is private.
{code:java} /** * Observes domain updates. * * @param update an observed domain update. */ private void onUpdate(@Observes @DomainLayer Update update) {...}
{code}
I've logged the stack trace when this observer is invoked:
{code:java} at steappe.micro.chassis.infra.persistence.DomainHistoryService.onUpdate(DomainHistoryService.java:185) [micro-chassis-1.0-SNAPSHOT.jar:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:564) ~[?:?] at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:95) [weld-core-impl-3.0.2.Final.jar:3.0.2.Final] at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:85) [weld-core-impl-3.0.2.Final.jar:3.0.2.Final] at org.jboss.weld.injection.MethodInvocationStrategy$SimpleMethodInvocationStrategy.invoke(MethodInvocationStrategy.java:129) [weld-core-impl-3.0.2.Final.jar:3.0.2.Final] at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:330) [weld-core-impl-3.0.2.Final.jar:3.0.2.Final] at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:308) [weld-core-impl-3.0.2.Final.jar:3.0.2.Final] at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:286) [weld-core-impl-3.0.2.Final.jar:3.0.2.Final] at javax.enterprise.inject.spi.ObserverMethod.notify(ObserverMethod.java:124) [cdi-api-2.0.jar:${parsedVersion.osgiVersion}] at org.jboss.weld.util.Observers.notify(Observers.java:166) [weld-core-impl-3.0.2.Final.jar:3.0.2.Final] at org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:285) [weld-core-impl-3.0.2.Final.jar:3.0.2.Final] at org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:273) [weld-core-impl-3.0.2.Final.jar:3.0.2.Final] at org.jboss.weld.event.EventImpl.fire(EventImpl.java:96) [weld-core-impl-3.0.2.Final.jar:3.0.2.Final] at steappe.preparation.infra.PreparationApplicationService.onStartup(PreparationApplicationService.java:231) [classes/:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:564) ~[?:?] at org.jboss.weld.interceptor.proxy.TerminalAroundInvokeInvocationContext.proceedInternal(TerminalAroundInvokeInvocationContext.java:51) [weld-core-impl-3.0.2.Final.jar:3.0.2.Final] at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:78) [weld-core-impl-3.0.2.Final.jar:3.0.2.Final] at steappe.micro.chassis.infra.interceptors.AbstractScheduledMethodInterceptor.proceed(AbstractScheduledMethodInterceptor.java:22) [micro-chassis-1.0-SNAPSHOT.jar:?] at steappe.micro.chassis.infra.interceptors.ScheduledTransactionalMethodInterceptor.doIntercept(ScheduledTransactionalMethodInterceptor.java:81) [micro-chassis-1.0-SNAPSHOT.jar:?] at steappe.micro.chassis.infra.interceptors.ScheduledTransactionalMethodInterceptor.lambda$intercept$0(ScheduledTransactionalMethodInterceptor.java:50) [micro-chassis-1.0-SNAPSHOT.jar:?]
{code}
As you can see, the stack trace is a bit different. This should help you analyzing this issue. |
|