This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-impl.git
The following commit(s) were added to refs/heads/master by this push:
new c7506f3 SLING-13143 fixes: Missing optional interface dependency
causes NoClassDefFoundError in Sling Models (#85)
c7506f3 is described below
commit c7506f3fed9e99144e96f3066ad867f9dbad177f
Author: subi <[email protected]>
AuthorDate: Mon Mar 30 17:20:56 2026 +0200
SLING-13143 fixes: Missing optional interface dependency causes
NoClassDefFoundError in Sling Models (#85)
---
.../models/impl/ModelPackageBundleListener.java | 2 +-
.../impl/ModelPackageBundleListenerTest.java | 16 ++++++++++++++
.../testmodels/classes/ClassWithMissingClass.java | 25 ++++++++++++++++++++++
.../models/testmodels/classes/MissingClass.java | 21 ++++++++++++++++++
4 files changed, 63 insertions(+), 1 deletion(-)
diff --git
a/src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java
b/src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java
index b08b7e3..e9042be 100644
--- a/src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java
+++ b/src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java
@@ -193,7 +193,7 @@ public class ModelPackageBundleListener implements
BundleTrackerCustomizer<Servi
}
}
}
- } catch (ClassNotFoundException | AnnotationFormatError e) {
+ } catch (NoClassDefFoundError | ClassNotFoundException |
AnnotationFormatError e) {
log.warn(
"Unable to load class '{}' from bundle '{}': {}",
className,
diff --git
a/src/test/java/org/apache/sling/models/impl/ModelPackageBundleListenerTest.java
b/src/test/java/org/apache/sling/models/impl/ModelPackageBundleListenerTest.java
index 56449a1..28481b4 100644
---
a/src/test/java/org/apache/sling/models/impl/ModelPackageBundleListenerTest.java
+++
b/src/test/java/org/apache/sling/models/impl/ModelPackageBundleListenerTest.java
@@ -103,6 +103,22 @@ class ModelPackageBundleListenerTest {
"Model should not yet have been registered but was");
}
+ @Test
+ void testAddingBundleWithLinkageError() throws ClassNotFoundException {
+ ClassLoader classLoader = new HideClassesClassLoader(
+ this.getClass().getClassLoader(),
+
org.apache.sling.models.testmodels.classes.MissingClass.class.getName());
+
+ ModelPackageBundleListener listener = createListenerForBundleWithClass(
+ classLoader,
org.apache.sling.models.testmodels.classes.ClassWithMissingClass.class.getName());
+
+ listener.addingBundle(mockBundle, new BundleEvent(BundleEvent.STARTED,
mockBundle));
+ assertFalse(
+ adapterImplementations.isModelClass(
+
org.apache.sling.models.testmodels.classes.ClassWithMissingClass.class),
+ "Model should not yet have been registered but was");
+ }
+
private ModelPackageBundleListener
createListenerForBundleWithClass(Class<?> modelClass)
throws ClassNotFoundException {
return createListenerForBundleWithClass(modelClass.getClassLoader(),
modelClass.getName());
diff --git
a/src/test/java/org/apache/sling/models/testmodels/classes/ClassWithMissingClass.java
b/src/test/java/org/apache/sling/models/testmodels/classes/ClassWithMissingClass.java
new file mode 100644
index 0000000..b436cbe
--- /dev/null
+++
b/src/test/java/org/apache/sling/models/testmodels/classes/ClassWithMissingClass.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.sling.models.testmodels.classes;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.models.annotations.Model;
+
+@Model(adaptables = Resource.class)
+public class ClassWithMissingClass implements MissingClass {}
diff --git
a/src/test/java/org/apache/sling/models/testmodels/classes/MissingClass.java
b/src/test/java/org/apache/sling/models/testmodels/classes/MissingClass.java
new file mode 100644
index 0000000..354391f
--- /dev/null
+++ b/src/test/java/org/apache/sling/models/testmodels/classes/MissingClass.java
@@ -0,0 +1,21 @@
+/*
+ * 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.sling.models.testmodels.classes;
+
+public interface MissingClass {}