2 Replies Latest reply on Sep 7, 2015 8:06 AM by Marcel Šebek

    Incompatibility of java 8u60, CDI observer method and lambda expressions

    Marcel Šebek Newbie

      Hi.

       

      It seems that java release 8u60 breaks the following scenario. Create an CDI observer method, write a lambda expression inside it, and use the observed parameter inside the lambda.

       

      Here is a short example:

       

      public void handle(@Observes SomeEvent event) {

              someMethod(optional.ifPresent(param -> {

                      switch (event.getType()) {

                              case A:

                                      param.A();

                                      break;

                      }

              });

      }

       

      The resulting error may differ, but basically I got the following two types of error during deployment:

       

      Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-000088: Observer method must be static or local business method:  [EnhancedAnnotatedMethodImpl] private Handler.lambda$handle$150(@Observes SomeEvent, Param) on [EnhancedAnnotatedTypeImpl] public @Singleton @ConcurrencyManagement class Handler

              at org.jboss.weld.bean.SessionBean.checkObserverMethods(SessionBean.java:205)

              at org.jboss.weld.bean.SessionBean.internalInitialize(SessionBean.java:100)

              at org.jboss.weld.bean.RIBean.initialize(RIBean.java:69)

              at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$5.doWork(ConcurrentBeanDeployer.java:121)

              at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$5.doWork(ConcurrentBeanDeployer.java:118)

              at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)

              at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)

              at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_60]

              ... 3 more

       

       

      Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type Param with qualifiers @Default

        at injection point [BackedAnnotatedParameter] Parameter 3 of [BackedAnnotatedMethod] private static Handler.lambda$handle$210(@Observes SomeEvent, Param)

        at Handler.lambda$handle$210(Handler.java:0)

      WELD-001475: The following beans match by type, but none have matching qualifiers:

        - Session bean [class SomeParam with qualifiers [@Provider @Any]; local interfaces are [Param]

       

              at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:359)

              at org.jboss.weld.bootstrap.ConcurrentValidator$4.doWork(ConcurrentValidator.java:108)

              at org.jboss.weld.bootstrap.ConcurrentValidator$4.doWork(ConcurrentValidator.java:103)

              at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)

              at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)

              at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_60]

              ... 3 more

       

      The type of error depends on the fact whether the bean of type @Default Param is available or not.

       

      I guess that this regression might be related to one of those fixes, but there are several other fixes related to lambdas:

      http://bugs.java.com/view_bug.do?bug_id=8037546

      http://bugs.java.com/view_bug.do?bug_id=8058227

       

      I use gradle for compilation, and '-parameters' parameter is not passed to javac. I run on wildfly 9.0.1.

       

      This may be a bug both in weld or in javac, I cannot decide. Any suggestions where to report this bug are welcome.