Hi Folks,

I work in the IBM CDI implementation team.

We are running the CDI 2.0 TCK/CDS and get a test failure on:

org.jboss.cdi.tck.tests.extensions.lifecycle.broken.observerMethod.ObserverMethodWithoutNotifyMethodTest

that I need some advice on.

The test has:  

import javax.enterprise.inject.spi.DeploymentException;
       
    @ShouldThrowException(DeploymentException.class)


    // unable to process ObserverMethodConfigurator due to missing notify method impl
    @Test
    @SpecAssertions({ @SpecAssertion(section = AFTER_BEAN_DISCOVERY, id = "ee") })
    public void unableToProcessObserverMethodConfigurator() {
    }

This behaviour is specified in
   https://docs.jboss.org/cdi/spec/2.0/cdi-spec-with-assertions.html#after_bean_discovery
(search for "ee)" )

ee) If the container is unable to process the ObserverMethodConfigurator it automatically detects the problem and treats it as a deployment problem.
ObserverMethodWithoutNotifyMethodTest.unableToProcessObserverMethodConfigurator()


However what we see coming back from Weld is not a javax DeploymentException but a javax DefinitionException wrapping a weld DeploymentException cause

Stack Dump = javax.enterprise.inject.spi.DefinitionException: org.jboss.weld.exceptions.DeploymentException: WELD-000179: ObserverMethodConfigurator created by org.jboss.cdi.tck.tests.extensions.lifecycle.broken.observerMethod.AfterBeanDiscoveryObserver@d31423c cannot be processed
        at org.jboss.weld.bootstrap.events.AfterBeanDiscoveryImpl.finish(AfterBeanDiscoveryImpl.java:180)                                 <<<<<<< Problem????
        at org.jboss.weld.bootstrap.events.AfterBeanDiscoveryImpl.fire(AfterBeanDiscoveryImpl.java:76)
        at org.jboss.weld.bootstrap.WeldStartup.deployBeans(WeldStartup.java:446)
        at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:83)
        at com.ibm.ws.cdi.impl.CDIContainerImpl.startInitialization(CDIContainerImpl.java:149)
        at com.ibm.ws.cdi.liberty.CDIRuntimeImpl.applicationStarting(CDIRuntimeImpl.java:400)
        at com.ibm.ws.container.service.state.internal.ApplicationStateManager.fireStarting(ApplicationStateManager.java:28)
        at com.ibm.ws.container.service.state.internal.StateChangeServiceImpl.fireApplicationStarting(StateChangeServiceImpl.java:50)
        at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.preDeployApp(DeployedAppInfoBase.java:383)
        at com.ibm.ws.app.manager.module.internal.DeployedAppInfoBase.deployApp(DeployedAppInfoBase.java:412)
        at com.ibm.ws.app.manager.war.internal.WARApplicationHandlerImpl.install(WARApplicationHandlerImpl.java:65)
        at com.ibm.ws.app.manager.internal.statemachine.StartAction.execute(StartAction.java:140)
        at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.enterState(ApplicationStateMachineImpl.java:1258)
        at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.run(ApplicationStateMachineImpl.java:873)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-000179: ObserverMethodConfigurator created by org.jboss.cdi.tck.tests.extensions.lifecycle.broken.observerMethod.AfterBeanDiscoveryObserver@d31423c cannot be processed
        at org.jboss.weld.bootstrap.events.AfterBeanDiscoveryImpl$ObserverRegistration.initObserverMethod(AfterBeanDiscoveryImpl.java:368)
        at org.jboss.weld.bootstrap.events.AfterBeanDiscoveryImpl.processObserverRegistration(AfterBeanDiscoveryImpl.java:268)
        at org.jboss.weld.bootstrap.events.AfterBeanDiscoveryImpl.finish(AfterBeanDiscoveryImpl.java:177)
        ... 16 more
Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-000415: Custom implementation of observer method does not override either notify(T) or notify(EventContext<T>): org.jboss.weld.bootstrap.events.configurator.ObserverMethodConfiguratorImpl@7e164c01
        at org.jboss.weld.bootstrap.events.configurator.ObserverMethodConfiguratorImpl$ImmutableObserverMethod.<init>(ObserverMethodConfiguratorImpl.java:272)
        at org.jboss.weld.bootstrap.events.configurator.ObserverMethodConfiguratorImpl.complete(ObserverMethodConfiguratorImpl.java:234)
        at org.jboss.weld.bootstrap.events.AfterBeanDiscoveryImpl$ObserverRegistration.initObserverMethod(AfterBeanDiscoveryImpl.java:366)
        ... 18 more


We can see the AfterBeanDiscoveryImpl.java:180 being

    /**
     * Bean and observer registration is delayed until after all {@link AfterBeanDiscovery} observers are notified.
     */
    private void finish() {
        try {
            GlobalEnablementBuilder globalEnablementBuilder = getBeanManager().getServices().get(GlobalEnablementBuilder.class);
            for (BeanRegistration registration : additionalBeans) {
                processBeanRegistration(registration, globalEnablementBuilder);
            }
            for (ObserverRegistration registration : additionalObservers) {
                processObserverRegistration(registration);
            }
        } catch (Exception e) {
            throw new DefinitionException(e);     <<<<<<  line 180
        }
    }


I am also aware of, in http://docs.jboss.org/cdi/spec/2.0/cdi-spec.pdf 11.5.3.,
    "If any observer method of the AfterBeanDiscovery event throws an exception, the exception is treated as a definition error by the container"

So why is the test expecting DeploymentException

import javax.enterprise.inject.spi.DeploymentException;
...      @ShouldThrowException(DeploymentException.class)


It seems like the test is seeing
    @SpecAssertions({ @SpecAssertion(section = AFTER_BEAN_DISCOVERY, id = "ee") })
        If the container is unable to process the ObserverMethodConfigurator it automatically detects the problem and treats it as a deployment problem.
as dominant but the weld implementation is seeing
       http://docs.jboss.org/cdi/spec/2.0/cdi-spec.pdf: 11.5.3
       If any observer method of the AfterBeanDiscovery event throws an exception, the exception is treated as a definition error by the container"
as dominant.

....and the two do not agree.

So the bottom line is the CDI CTS/TCK test
    org.jboss.cdi.tck.tests.extensions.lifecycle.broken.observerMethod.ObserverMethodWithoutNotifyMethodTest
fails due to the inconsistency.

Have I missunderstood the spec contradiction or missed some part of Weld integration needed?

Gordon.