You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Konrad Windszus (Jira)" <ji...@apache.org> on 2021/11/24 14:00:00 UTC
[jira] [Updated] (SLING-10935) OSGi Mock: Improve error message when mandatory references cannot be resolved for constructor injection
[ https://issues.apache.org/jira/browse/SLING-10935?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Konrad Windszus updated SLING-10935:
------------------------------------
Summary: OSGi Mock: Improve error message when mandatory references cannot be resolved for constructor injection (was: Improve error message when mandatory references cannot be resolved for constructor injection)
> OSGi Mock: Improve error message when mandatory references cannot be resolved for constructor injection
> -------------------------------------------------------------------------------------------------------
>
> Key: SLING-10935
> URL: https://issues.apache.org/jira/browse/SLING-10935
> Project: Sling
> Issue Type: Improvement
> Components: Testing
> Affects Versions: Testing OSGi Mock 3.1.4
> Reporter: Konrad Windszus
> Assignee: Konrad Windszus
> Priority: Major
> Fix For: Testing OSGi Mock 3.1.6
>
> Time Spent: 1h 20m
> Remaining Estimate: 0h
>
> When constructor injection is used and a reference is only used as argument to the constructor it gets an automatically generated [reference name|http://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.component.html#org.osgi.service.component.annotations.Reference.name--] by Bnd like {{$001}} (as constructor parameter names are not available in class files, https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Executable.html#getParameters--) which leads to the following error message when a reference cannot be injected:
> {code}
> org.apache.sling.testing.mock.osgi.ReferenceViolationException: Unable to inject mandatory reference '$001' for class <MyDSComponentClass> : no matching services were found.
> at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.buildConstructorInjectionValue(OsgiServiceUtil.java:568)
> at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.buildConstructorInjectionValues(OsgiServiceUtil.java:533)
> at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.instantiateServiceWithActivateInject(OsgiServiceUtil.java:493)
> at org.apache.sling.testing.mock.osgi.OsgiServiceUtil.activateInjectServices(OsgiServiceUtil.java:456)
> at org.apache.sling.testing.mock.osgi.MockOsgi.activateInjectServices(MockOsgi.java:190)
> at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:191)
> at org.apache.sling.testing.mock.osgi.context.OsgiContextImpl.registerInjectActivateService(OsgiContextImpl.java:179)
> ...
> {code}
> In addition to the reference name the to be injected class should be emitted and also it should be mentioned that a constructor argument cannot be resolved.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)