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}
|
|