This is an automated email from the ASF dual-hosted git repository.

struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git

commit 45e578719e6865da9b58722268e880933e717019
Author: Mark Struberg <[email protected]>
AuthorDate: Mon Oct 14 12:56:48 2024 +0200

    OWB-1441 fix exception if custom interceptor has no default ct
---
 .../webbeans/portable/InjectionTargetImpl.java     | 22 +++++++++++++---------
 .../interceptorbean/BigBrotherInterceptor.java     |  6 ++++++
 .../interceptorbean/BigBrotherInterceptorBean.java |  2 +-
 .../owb1441/CustomInterceptorTest.java             |  5 +----
 .../test/interceptors/owb1441/WatchExtension.java  |  3 +--
 .../interceptors/owb1441/WatchInterceptor.java     | 16 ++++++++++++++++
 .../interceptors/owb1441/WatchInterceptorBean.java |  4 +---
 .../web/tomcat7/test/OwbTomcatPluginIT.java        |  3 +--
 8 files changed, 40 insertions(+), 21 deletions(-)

diff --git 
a/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
 
b/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
index 875b79a44..28d802c2b 100644
--- 
a/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
+++ 
b/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
@@ -21,7 +21,6 @@ package org.apache.webbeans.portable;
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
-import org.apache.webbeans.exception.WebBeansCreationException;
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.inject.InjectableConstructor;
 import org.apache.webbeans.inject.InjectableField;
@@ -140,16 +139,20 @@ public class InjectionTargetImpl<T> extends 
AbstractProducer<T> implements Injec
         // no more needed
         interceptorInfo.getClassCdiInterceptors().clear();
 
-        InterceptorResolutionService.BusinessMethodInterceptorInfo 
constructorInterceptorInfo =
-                                
interceptorInfo.getConstructorInterceptorInfos().get(getConstructor().getJavaMember());
-        Interceptor<?>[] constructorEjbInterceptorArray = 
constructorInterceptorInfo == null ?
-                                            null : 
constructorInterceptorInfo.getEjbInterceptors();
-        List<Interceptor<?>> constructorEjbInterceptors = 
constructorEjbInterceptorArray == null ?
-                                            
Collections.<Interceptor<?>>emptyList() : 
asList(constructorEjbInterceptorArray);
-        aroundConstructInterceptors = getLifecycleInterceptors(
+        final AnnotatedConstructor<T> ct = getConstructor();
+        if (ct != null)
+        {
+            InterceptorResolutionService.BusinessMethodInterceptorInfo 
constructorInterceptorInfo =
+                
interceptorInfo.getConstructorInterceptorInfos().get(ct.getJavaMember());
+            Interceptor<?>[] constructorEjbInterceptorArray = 
constructorInterceptorInfo == null ?
+                null : constructorInterceptorInfo.getEjbInterceptors();
+            List<Interceptor<?>> constructorEjbInterceptors = 
constructorEjbInterceptorArray == null ?
+                Collections.<Interceptor<?>>emptyList() : 
asList(constructorEjbInterceptorArray);
+            aroundConstructInterceptors = getLifecycleInterceptors(
                 constructorEjbInterceptors,
                 interceptorInfo.getConstructorCdiInterceptors(),
                 InterceptionType.AROUND_CONSTRUCT);
+        }
     }
 
     @Override
@@ -395,7 +398,8 @@ public class InjectionTargetImpl<T> extends 
AbstractProducer<T> implements Injec
         Constructor<T> defaultConstructor = getDefaultConstructor();
         if (defaultConstructor == null)
         {
-            throw new WebBeansCreationException("No default constructor for " 
+ annotatedType.getJavaClass().getName());
+            // sometimes there is no default ct nor any injection point ct
+            return null;
         }
         return new AnnotatedConstructorImpl<>(webBeansContext, 
defaultConstructor, annotatedType);
     }
diff --git 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/interceptorbean/BigBrotherInterceptor.java
 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/interceptorbean/BigBrotherInterceptor.java
index 784435bad..7065b22e6 100644
--- 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/interceptorbean/BigBrotherInterceptor.java
+++ 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/interceptorbean/BigBrotherInterceptor.java
@@ -26,6 +26,12 @@ public class BigBrotherInterceptor
 {
     private static boolean observed = false;
 
+
+    public BigBrotherInterceptor(int 
totallyUselessParamJustToNotHaveADefaultCt)
+    {
+        // all fine ;)
+    }
+
     public Object invoke(InvocationContext context) throws Exception
     {
         System.out.println("Big Brother is watching you " + 
context.getMethod());
diff --git 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/interceptorbean/BigBrotherInterceptorBean.java
 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/interceptorbean/BigBrotherInterceptorBean.java
index d0b745797..d51c0423d 100644
--- 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/interceptorbean/BigBrotherInterceptorBean.java
+++ 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/interceptorbean/BigBrotherInterceptorBean.java
@@ -75,7 +75,7 @@ public class BigBrotherInterceptorBean implements 
Interceptor<BigBrotherIntercep
     @Override
     public BigBrotherInterceptor 
create(CreationalContext<BigBrotherInterceptor> creationalContext)
     {
-        return new BigBrotherInterceptor();
+        return new BigBrotherInterceptor(42);
     }
 
     @Override
diff --git 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/CustomInterceptorTest.java
 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/CustomInterceptorTest.java
index 0efcced3c..3230e371a 100644
--- 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/CustomInterceptorTest.java
+++ 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/CustomInterceptorTest.java
@@ -18,9 +18,6 @@ package org.apache.webbeans.test.interceptors.owb1441;
 
 import jakarta.enterprise.context.ApplicationScoped;
 import org.apache.webbeans.test.AbstractUnitTest;
-import 
org.apache.webbeans.test.interceptors.interceptorbean.BigBrotherInterceptor;
-import org.apache.webbeans.test.interceptors.interceptorbean.BigBrothered;
-import 
org.apache.webbeans.test.interceptors.interceptorbean.BigBrotheredExtension;
 import org.junit.Test;
 
 import static org.junit.Assert.assertTrue;
@@ -47,7 +44,7 @@ public class CustomInterceptorTest extends AbstractUnitTest
     }
 
     @ApplicationScoped
-    @BigBrothered
+    @Watched
     public static class LittleJohnDoe
     {
         public void makeACoffee() {
diff --git 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/WatchExtension.java
 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/WatchExtension.java
index 7c3738908..34e78172c 100644
--- 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/WatchExtension.java
+++ 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/WatchExtension.java
@@ -35,8 +35,7 @@ import jakarta.enterprise.inject.spi.BeanManager;
 import jakarta.enterprise.inject.spi.BeforeBeanDiscovery;
 import jakarta.enterprise.inject.spi.Extension;
 import jakarta.enterprise.util.Nonbinding;
-import 
org.apache.webbeans.test.interceptors.interceptorbean.BigBrotherInterceptorBean;
-import org.apache.webbeans.test.interceptors.interceptorbean.BigBrothered;
+
 
 public class WatchExtension implements Extension
 {
diff --git 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/WatchInterceptor.java
 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/WatchInterceptor.java
index 38512d245..8bf58b012 100644
--- 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/WatchInterceptor.java
+++ 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/WatchInterceptor.java
@@ -1,3 +1,19 @@
+/*
+ * 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.webbeans.test.interceptors.owb1441;
 
 import jakarta.interceptor.AroundInvoke;
diff --git 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/WatchInterceptorBean.java
 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/WatchInterceptorBean.java
index bdfdcfba6..f91b83815 100644
--- 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/WatchInterceptorBean.java
+++ 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/owb1441/WatchInterceptorBean.java
@@ -29,15 +29,13 @@ import jakarta.enterprise.inject.spi.Interceptor;
 import jakarta.enterprise.util.AnnotationLiteral;
 import jakarta.interceptor.InvocationContext;
 import org.apache.webbeans.annotation.DefaultLiteral;
-import 
org.apache.webbeans.test.interceptors.interceptorbean.BigBrotherInterceptor;
-import org.apache.webbeans.test.interceptors.interceptorbean.BigBrothered;
 
 public class WatchInterceptorBean implements Interceptor<WatchInterceptor>
 {
     // it's good performance practice to keep the sets static as they are 
requested tons of times!
     public static final Set<Type> TYPES = Set.of(WatchInterceptor.class);
     public static final Set<Annotation> QUALIFIERS = 
Set.of(DefaultLiteral.INSTANCE);
-    public static final Set<Annotation> INTERCEPTOR_BINDINGS = Set.of(new 
AnnotationLiteral<BigBrothered>() {});
+    public static final Set<Annotation> INTERCEPTOR_BINDINGS = Set.of(new 
AnnotationLiteral<Watched>() {});
 
     public WatchInterceptorBean(int totallyUselessParamJustToNotHaveADefaultCt)
     {
diff --git 
a/webbeans-tomcat/src/it/servletinjection/src/test/java/org/apache/webbeans/web/tomcat7/test/OwbTomcatPluginIT.java
 
b/webbeans-tomcat/src/it/servletinjection/src/test/java/org/apache/webbeans/web/tomcat7/test/OwbTomcatPluginIT.java
index 44db7e739..2b54f33fa 100644
--- 
a/webbeans-tomcat/src/it/servletinjection/src/test/java/org/apache/webbeans/web/tomcat7/test/OwbTomcatPluginIT.java
+++ 
b/webbeans-tomcat/src/it/servletinjection/src/test/java/org/apache/webbeans/web/tomcat7/test/OwbTomcatPluginIT.java
@@ -56,5 +56,4 @@ public class OwbTomcatPluginIT
         Assert.assertNotNull(response);
         Assert.assertEquals("Got " + builder.toString(), 200, 
response.getStatusLine().getStatusCode());
     }
-
-}
+}
\ No newline at end of file

Reply via email to