You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2017/03/09 15:51:11 UTC

tomee git commit: TOMEE-2020 avoid npe if ejb is vetoed

Repository: tomee
Updated Branches:
  refs/heads/master 569e604a1 -> 933bd899d


TOMEE-2020 avoid npe if ejb is vetoed


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/933bd899
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/933bd899
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/933bd899

Branch: refs/heads/master
Commit: 933bd899dfe8ec54db1af29e97c39c03e35b1000
Parents: 569e604
Author: rmannibucau <rm...@apache.org>
Authored: Thu Mar 9 16:51:05 2017 +0100
Committer: rmannibucau <rm...@apache.org>
Committed: Thu Mar 9 16:51:05 2017 +0100

----------------------------------------------------------------------
 .../apache/openejb/cdi/OpenEJBLifecycle.java    |  4 +-
 .../org/apache/openejb/cdi/EJBVetoTest.java     | 54 ++++++++++++++++++++
 2 files changed, 56 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/933bd899/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
index 61b7f1f..6fec759 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
@@ -204,13 +204,13 @@ public class OpenEJBLifecycle implements ContainerLifecycle {
 
             final Collection<Class<?>> ejbs = new ArrayList<>(stuff.getBeanContexts().size());
             for (final BeanContext bc : stuff.getBeanContexts()) {
+                ejbs.add(bc.getManagedClass());
+
                 final CdiEjbBean cdiEjbBean = bc.get(CdiEjbBean.class);
                 if (cdiEjbBean == null) {
                     continue;
                 }
 
-                ejbs.add(bc.getManagedClass());
-
                 if (AbstractProducer.class.isInstance(cdiEjbBean)) {
                     AbstractProducer.class.cast(cdiEjbBean).defineInterceptorStack(cdiEjbBean, cdiEjbBean.getAnnotatedType(), cdiEjbBean.getWebBeansContext());
                 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/933bd899/container/openejb-core/src/test/java/org/apache/openejb/cdi/EJBVetoTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/cdi/EJBVetoTest.java b/container/openejb-core/src/test/java/org/apache/openejb/cdi/EJBVetoTest.java
new file mode 100644
index 0000000..d13e935
--- /dev/null
+++ b/container/openejb-core/src/test/java/org/apache/openejb/cdi/EJBVetoTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.cdi;
+
+import org.apache.openejb.testing.ApplicationComposers;
+import org.apache.openejb.testing.CdiExtensions;
+import org.apache.openejb.testing.Classes;
+import org.junit.Test;
+
+import javax.ejb.Singleton;
+import javax.ejb.Startup;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import java.util.concurrent.Callable;
+
+@CdiExtensions(EJBVetoTest.Vetoer.class)
+@Classes(cdi = true, innerClassesAsBean = true)
+public class EJBVetoTest {
+    @Test
+    public void run() throws Exception { // https://issues.apache.org/jira/browse/TOMEE-2020, we just check we get no NPE
+        new ApplicationComposers(EJBVetoTest.class).evaluate(this, new Callable<Object>() {
+            @Override
+            public Object call() throws Exception {
+                return null;
+            }
+        });
+    }
+
+    public static class Vetoer implements Extension {
+        void pat(@Observes final ProcessAnnotatedType<ToVeto> pat) {
+            pat.veto();
+        }
+    }
+
+    @Startup
+    @Singleton
+    public static class ToVeto {
+    }
+}