You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "subiron (via GitHub)" <gi...@apache.org> on 2026/03/23 18:52:40 UTC

[PR] SLING-13143 - Missing optional interface dependency causes NoClassDefFoundError and stops initialising other models [sling-org-apache-sling-models-impl]

subiron opened a new pull request, #85:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/85

   https://issues.apache.org/jira/browse/SLING-13143 
   
   > The issue is nearly identical to [SLING-6764](https://issues.apache.org/jira/browse/SLING-6764), but specifically triggered by a NoClassDefFoundError when an implementation class is present, but an interface it implements is missing at runtime.
   > 
   > Context: This scenario occurs when dependencies are marked as optional (present during compilation but missing in specific runtime environments). While the absence of the model itself is expected in these environments, it currently prevents other valid models from being initialized.
   > 
   > Steps to reproduce:
   > 
   > Define a Sling Model that implements an interface from an optional dependency.
   > Deploy the bundle to an environment where the optional dependency (the interface) is missing.
   > Observe that NoClassDefFoundError is thrown during the scanning/registration process.
   > 
   > Observed Behavior: The NoClassDefFoundError is not caught by the injector/registrar, causing a failure that halts the initialization of other models.
   > 
   > Expected Behavior: Similar to the fix in [SLING-6764](https://issues.apache.org/jira/browse/SLING-6764), NoClassDefFoundError should be caught and logged as a warning/error. The failure to load one model due to missing optional dependencies should not impact the availability of other models in the system.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-13143 - Missing optional interface dependency causes NoClassDefFoundError and stops initialising other models [sling-org-apache-sling-models-impl]

Posted by "bkkothari2255 (via GitHub)" <gi...@apache.org>.
bkkothari2255 commented on code in PR #85:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/85#discussion_r2995659845


##########
src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java:
##########
@@ -200,6 +200,13 @@ private void analyzeClass(Bundle bundle, String className, List<ServiceRegistrat
                     bundle.getSymbolicName(),
                     e.getLocalizedMessage(),
                     e);
+        } catch (LinkageError e) {
+            log.error(

Review Comment:
   @subiron The updated code handles it well, warn for `NoClassDefFoundError` is the right signal for a missing optional dep. If other LinkageError subtypes ever need different handling, a separate catch block can be added later without touching this.
   Only thing still pending is the test - a second healthy model asserting it still registers after the error would prove the fix end to end. Apologies, I should have caught this earlier in the review



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-13143 - Missing optional interface dependency causes NoClassDefFoundError and stops initialising other models [sling-org-apache-sling-models-impl]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #85:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/85#issuecomment-4129569175

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-models-impl&pullRequest=85) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-models-impl&pullRequest=85&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-models-impl&pullRequest=85&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-models-impl&pullRequest=85&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-models-impl&pullRequest=85&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-models-impl&pullRequest=85&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-models-impl&pullRequest=85)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-13143 - Missing optional interface dependency causes NoClassDefFoundError and stops initialising other models [sling-org-apache-sling-models-impl]

Posted by "stefanseifert (via GitHub)" <gi...@apache.org>.
stefanseifert merged PR #85:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/85


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-13143 - Missing optional interface dependency causes NoClassDefFoundError and stops initialising other models [sling-org-apache-sling-models-impl]

Posted by "bkkothari2255 (via GitHub)" <gi...@apache.org>.
bkkothari2255 commented on code in PR #85:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/85#discussion_r2981418482


##########
src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java:
##########
@@ -200,6 +200,13 @@ private void analyzeClass(Bundle bundle, String className, List<ServiceRegistrat
                     bundle.getSymbolicName(),
                     e.getLocalizedMessage(),
                     e);
+        } catch (LinkageError e) {

Review Comment:
   Hey, I've seen this pattern cause headaches in AEM projects before. `LinkageError` is quite a wide net — it'll also swallow things like `IncompatibleClassChangeError` and `VerifyError` which usually mean something is genuinely broken in the model, not just an optional dep that's missing.
   
   In our case the missing interface scenario from SLING-13143 will always throw `NoClassDefFoundError` specifically, so I'd narrow this down:
   
   `catch (NoClassDefFoundError e)`
   
   Otherwise we risk debugging a broken model for hours not realizing the framework quietly swallowed the real error.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-13143 - Missing optional interface dependency causes NoClassDefFoundError and stops initialising other models [sling-org-apache-sling-models-impl]

Posted by "subiron (via GitHub)" <gi...@apache.org>.
subiron commented on code in PR #85:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/85#discussion_r2990893831


##########
src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java:
##########
@@ -200,6 +200,13 @@ private void analyzeClass(Bundle bundle, String className, List<ServiceRegistrat
                     bundle.getSymbolicName(),
                     e.getLocalizedMessage(),
                     e);
+        } catch (LinkageError e) {
+            log.error(

Review Comment:
   Hi, thanks for your feedback.
   I was actually wondering, “what kind of error should cause the processing of the remaining models to be suspended”? In my opinion, there isn’t such a case, but anything related to a `LinkageError` should catch the developer’s attention, which is why I reported it as a bug.
   I implemented the suggested changes because the error concerns only a missing interface—but I’m still wondering what would be a better solution in most cases 
   
   Translated with DeepL.com (free version)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-13143 - Missing optional interface dependency causes NoClassDefFoundError and stops initialising other models [sling-org-apache-sling-models-impl]

Posted by "bkkothari2255 (via GitHub)" <gi...@apache.org>.
bkkothari2255 commented on code in PR #85:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/85#discussion_r2981436958


##########
src/main/java/org/apache/sling/models/impl/ModelPackageBundleListener.java:
##########
@@ -200,6 +200,13 @@ private void analyzeClass(Bundle bundle, String className, List<ServiceRegistrat
                     bundle.getSymbolicName(),
                     e.getLocalizedMessage(),
                     e);
+        } catch (LinkageError e) {
+            log.error(

Review Comment:
   Minor but in production environments, teams typically have alerting on `ERROR` logs — this will fire alerts every time a bundle with a missing optional dep is deployed. The `ClassNotFoundException` catch right above uses `warn` for the same kind of recoverable situation, so this should match.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-13143 - Missing optional interface dependency causes NoClassDefFoundError and stops initialising other models [sling-org-apache-sling-models-impl]

Posted by "stefanseifert (via GitHub)" <gi...@apache.org>.
stefanseifert commented on PR #85:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/85#issuecomment-4155877759

   thanks, lgtm


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] SLING-13143 - Missing optional interface dependency causes NoClassDefFoundError and stops initialising other models [sling-org-apache-sling-models-impl]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #85:
URL: https://github.com/apache/sling-org-apache-sling-models-impl/pull/85#issuecomment-4113256977

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-models-impl&pullRequest=85) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [1 New issue](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-models-impl&pullRequest=85&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_sling-org-apache-sling-models-impl&pullRequest=85&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_sling-org-apache-sling-models-impl&pullRequest=85&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-models-impl&pullRequest=85&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_sling-org-apache-sling-models-impl&pullRequest=85&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_sling-org-apache-sling-models-impl&pullRequest=85)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@sling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org