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

asf-gitbox-commits pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git

commit 515bde7c95f66aefe82e91447bc442254dccde04
Author: Mark Struberg <[email protected]>
AuthorDate: Sat Jul 4 16:59:55 2026 +0200

    add integration test for skipping classes on NoClassDefFound
    
    We do exclude Classes as bean candidates if they cannot be fully loaded.
    This is necessary if you have jars which contain optional features.
---
 .../src/it/{properties => noclassdeffound}/pom.xml | 28 +++------
 .../test/spi/deployer/NcdfAvailableBean.java       | 28 +++++++++
 .../webbeans/test/spi/deployer/NcdfBrokenBean.java | 30 +++++++++
 .../test/spi/deployer/NcdfMissingDependency.java   | 25 ++++++++
 .../test/spi/deployer/NoClassDefFoundBootTest.java | 72 ++++++++++++++++++++++
 .../src/test/resources/META-INF/beans.xml          | 19 ++++++
 webbeans-impl/src/it/properties/pom.xml            |  2 +-
 .../corespi/scanner/AbstractMetaDataDiscovery.java |  7 ---
 8 files changed, 183 insertions(+), 28 deletions(-)

diff --git a/webbeans-impl/src/it/properties/pom.xml 
b/webbeans-impl/src/it/noclassdeffound/pom.xml
similarity index 83%
copy from webbeans-impl/src/it/properties/pom.xml
copy to webbeans-impl/src/it/noclassdeffound/pom.xml
index 796811d91..d44e9166b 100644
--- a/webbeans-impl/src/it/properties/pom.xml
+++ b/webbeans-impl/src/it/noclassdeffound/pom.xml
@@ -1,34 +1,34 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
 <!--
-    
+
     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.
--->    
-    
+-->
+
     <modelVersion>4.0.0</modelVersion>
-    
+
     <parent>
         <groupId>org.apache.openwebbeans</groupId>
         <artifactId>openwebbeans</artifactId>
         <version>@pom.version@</version>
     </parent>
-    
+
     <groupId>org.apache.openwebbeans</groupId>
-    <artifactId>openwebbeans-impl-it</artifactId>
+    <artifactId>openwebbeans-impl-it-noclassdeffound</artifactId>
     <version>@pom.version@</version>
-  
+
     <dependencies>
         <dependency>
             <groupId>jakarta.annotation</groupId>
@@ -57,22 +57,10 @@
             <version>@pom.version@</version>
         </dependency>
 
-        <dependency>
-            <groupId>jakarta.annotation</groupId>
-            <artifactId>jakarta.annotation-api</artifactId>
-            <optional>true</optional>
-        </dependency>
-        <dependency>
-            <groupId>jakarta.interceptor</groupId>
-            <artifactId>jakarta.interceptor-api</artifactId>
-            <optional>true</optional>
-        </dependency>
-
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
-
     </dependencies>
 </project>
diff --git 
a/webbeans-impl/src/it/noclassdeffound/src/test/java/org/apache/webbeans/test/spi/deployer/NcdfAvailableBean.java
 
b/webbeans-impl/src/it/noclassdeffound/src/test/java/org/apache/webbeans/test/spi/deployer/NcdfAvailableBean.java
new file mode 100644
index 000000000..ff4ca296f
--- /dev/null
+++ 
b/webbeans-impl/src/it/noclassdeffound/src/test/java/org/apache/webbeans/test/spi/deployer/NcdfAvailableBean.java
@@ -0,0 +1,28 @@
+/*
+ * 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.spi.deployer;
+
+import jakarta.enterprise.context.ApplicationScoped;
+
+@ApplicationScoped
+public class NcdfAvailableBean
+{
+    public int meaningOfLife()
+    {
+        return 42;
+    }
+}
diff --git 
a/webbeans-impl/src/it/noclassdeffound/src/test/java/org/apache/webbeans/test/spi/deployer/NcdfBrokenBean.java
 
b/webbeans-impl/src/it/noclassdeffound/src/test/java/org/apache/webbeans/test/spi/deployer/NcdfBrokenBean.java
new file mode 100644
index 000000000..58b5d7dd5
--- /dev/null
+++ 
b/webbeans-impl/src/it/noclassdeffound/src/test/java/org/apache/webbeans/test/spi/deployer/NcdfBrokenBean.java
@@ -0,0 +1,30 @@
+/*
+ * 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.spi.deployer;
+
+import jakarta.enterprise.context.ApplicationScoped;
+
+@ApplicationScoped
+public class NcdfBrokenBean
+{
+    private final NcdfMissingDependency dependency = new 
NcdfMissingDependency();
+
+    public int meaningOfLife()
+    {
+        return dependency.meaningOfLife();
+    }
+}
diff --git 
a/webbeans-impl/src/it/noclassdeffound/src/test/java/org/apache/webbeans/test/spi/deployer/NcdfMissingDependency.java
 
b/webbeans-impl/src/it/noclassdeffound/src/test/java/org/apache/webbeans/test/spi/deployer/NcdfMissingDependency.java
new file mode 100644
index 000000000..b8a47ff0d
--- /dev/null
+++ 
b/webbeans-impl/src/it/noclassdeffound/src/test/java/org/apache/webbeans/test/spi/deployer/NcdfMissingDependency.java
@@ -0,0 +1,25 @@
+/*
+ * 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.spi.deployer;
+
+public class NcdfMissingDependency
+{
+    public int meaningOfLife()
+    {
+        return 0;
+    }
+}
diff --git 
a/webbeans-impl/src/it/noclassdeffound/src/test/java/org/apache/webbeans/test/spi/deployer/NoClassDefFoundBootTest.java
 
b/webbeans-impl/src/it/noclassdeffound/src/test/java/org/apache/webbeans/test/spi/deployer/NoClassDefFoundBootTest.java
new file mode 100644
index 000000000..2f8a55924
--- /dev/null
+++ 
b/webbeans-impl/src/it/noclassdeffound/src/test/java/org/apache/webbeans/test/spi/deployer/NoClassDefFoundBootTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.spi.deployer;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Set;
+
+import jakarta.enterprise.context.spi.CreationalContext;
+import jakarta.enterprise.inject.spi.Bean;
+import jakarta.enterprise.inject.spi.BeanManager;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.spi.ContainerLifecycle;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class NoClassDefFoundBootTest
+{
+    @Test
+    public void shouldIgnoreBeanWithMissingDependencyDuringBoot()
+    {
+        
deleteClassFile("org.apache.webbeans.test.spi.deployer.NcdfMissingDependency");
+
+        ContainerLifecycle containerLifecycle = 
WebBeansContext.getInstance().getService(ContainerLifecycle.class);
+        containerLifecycle.startApplication(null);
+
+        try
+        {
+            BeanManager beanManager = 
WebBeansContext.getInstance().getBeanManagerImpl();
+
+            final Set<Bean<?>> beans = 
beanManager.getBeans(NcdfAvailableBean.class);
+            Bean<NcdfAvailableBean> availableBean = (Bean<NcdfAvailableBean>) 
beanManager.resolve(beans);
+            Assert.assertNotNull(availableBean);
+            final CreationalContext<NcdfAvailableBean> cc = 
beanManager.createCreationalContext(availableBean);
+            NcdfAvailableBean instance = (NcdfAvailableBean) 
beanManager.getReference(availableBean, NcdfAvailableBean.class, cc);
+            Assert.assertEquals(42, instance.meaningOfLife());
+
+            
Assert.assertTrue(beanManager.getBeans(NcdfBrokenBean.class).isEmpty());
+        }
+        finally
+        {
+            containerLifecycle.stopApplication(null);
+        }
+    }
+
+    private void deleteClassFile(String className)
+    {
+        String classResourceName = "/" + className.replace('.', '/') + 
".class";
+        URL classResource = getClass().getResource(classResourceName);
+        if (classResource != null)
+        {
+            File classFile = new File(classResource.getFile());
+            Assert.assertTrue(classFile.exists());
+            Assert.assertTrue(classFile.delete());
+        }
+    }
+}
diff --git 
a/webbeans-impl/src/it/noclassdeffound/src/test/resources/META-INF/beans.xml 
b/webbeans-impl/src/it/noclassdeffound/src/test/resources/META-INF/beans.xml
new file mode 100644
index 000000000..7455494c7
--- /dev/null
+++ b/webbeans-impl/src/it/noclassdeffound/src/test/resources/META-INF/beans.xml
@@ -0,0 +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.
+-->
+<beans/>
diff --git a/webbeans-impl/src/it/properties/pom.xml 
b/webbeans-impl/src/it/properties/pom.xml
index 796811d91..096374070 100644
--- a/webbeans-impl/src/it/properties/pom.xml
+++ b/webbeans-impl/src/it/properties/pom.xml
@@ -26,7 +26,7 @@
     </parent>
     
     <groupId>org.apache.openwebbeans</groupId>
-    <artifactId>openwebbeans-impl-it</artifactId>
+    <artifactId>openwebbeans-impl-it-properties</artifactId>
     <version>@pom.version@</version>
   
     <dependencies>
diff --git 
a/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
 
b/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
index 13fe0fa9a..24f87fd4e 100644
--- 
a/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
+++ 
b/webbeans-impl/src/main/java/org/apache/webbeans/corespi/scanner/AbstractMetaDataDiscovery.java
@@ -490,13 +490,6 @@ public abstract class AbstractMetaDataDiscovery implements 
BdaScannerService
                         Class<?> clazz = ClassUtil.getClassFromName(className, 
loader, dontSkipNCDFT);
                         if (clazz != null)
                         {
-                            if (dontSkipNCDFT)
-                            {
-                                // try to provoke a NoClassDefFoundError 
exception which is thrown
-                                // if some dependencies of the class are 
missing
-                                clazz.getDeclaredFields();
-                            }
-
                             // we can add this class cause it has been loaded 
completely
                             classSet.add(clazz);
                         }

Reply via email to