It's all about the answers!

Ask a question

Cannot use inner class as configuration properties validator class


SEC Servizi (94622244) | asked Nov 08 '17, 10:06 a.m.
edited Nov 08 '17, 10:26 a.m.
Using an inner class:
public class ScheduledTask extends AbstractAutoScheduledTask {
    [...]
    public class ConfigurationPropertyValidator extends AbstractConfigurationPropertyValidator {
        [...]
    }
}
as validator class for configuration properties:
<prerequisites>
    <configurationProperties validatorClass="ScheduledTask$ConfigurationPropertyValidator">
    [...]

throws a class instantiation exception:

java.lang.InstantiationException: ScheduledTask$ConfigurationPropertyValidator
at java.lang.J9VMInternals.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1558)
at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:184)
at com.ibm.team.repository.service.internal.registry.ClientLocalizingRegistryStrategy.createExecutableExtension(ClientLocalizingRegistryStrategy.java:56)
at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:904)
at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:243)
at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:55)
at com.ibm.team.repository.service.internal.registry.ClientLocalizingConfigurationElement.createExecutableExtension(ClientLocalizingConfigurationElement.java:137)
at com.ibm.team.repository.common.transport.AbstractElementDescriptor.createInstance(AbstractElementDescriptor.java:254)
at com.ibm.team.repository.common.transport.internal.registry.ConfigurationPropertiesElementDescriptor.createValidatorInstance(ConfigurationPropertiesElementDescriptor.java:41)
... 174 more
If outer class simply implements the configuration properties validator interface, then methods cannot use services due to:
com.ibm.team.repository.common.transport.internal.registry.ServiceNotFoundException: The service 'ScheduledTask@7d757d75' failed to find the required service 'interface com.ibm.team.repository.common.service.IContributorService'.  Check <prerequisites> in plugin.xml.
        at com.ibm.team.repository.service.AbstractService.getService(AbstractService.java:788)
        at ScheduledTask.validateProperties(ScheduledTask.java:202)
even if these required services are defined in plugin.xml:
<prerequisites>
    [...]
    <requiredService interface="com.ibm.team.repository.common.service.IContributorService" />
</prerequisites>
Any advice?
Thanks in advance.
Cheers.

Accepted answer


permanent link
SEC Servizi (94622244) | answered Nov 13 '17, 10:26 a.m.
edited Nov 13 '17, 10:27 a.m.
If outer class simply implements the configuration properties validator interface, then methods cannot use services [...]

We figured out we have to implement IConfigurationPropertyValidator2 instead of IConfigurationPropertyValidator if we need services on our validator class.

public Map<String, IStatus> validateProperties( Map<String, Object> properties, boolean fast, Map<String, Object> services) {
    IContributorService contributorService = (IContributorService) services.get(IContributorService.class.getName());
(Nooby mistake since the same approach is required for accessing properties!)

Ralph Schoon selected this answer as the correct answer

2 other answers



permanent link
Lukas Steiger (3131422) | answered Nov 09 '17, 1:10 p.m.

 Hi SEC,


Defining IContributorService as a required interface is the way to go if you are working with IContributor related data. 
Have a look at our Secure User Property Store on GitHub which is also using a validator class:
  • Validator Class - implementation of the validator
  • plugin.xml - contains the plugin definition including the requiredService declaration and the validator class usage
  • MANIFEST.MF - ensure that you have imported all required packages
Depending on your needs, you might implement IConfigurationPropertyValidator instead of extending AbstractConfigurationPropertyValidator.


permanent link
SEC Servizi (94622244) | answered Nov 10 '17, 4:35 a.m.
edited Nov 10 '17, 6:29 a.m.
Defining IContributorService as a required interface is the way to go if you are working with IContributor related data. 
Yep, we need it to validate a property which have to contain user ID.

Depending on your needs, you might implement IConfigurationPropertyValidator instead of extending AbstractConfigurationPropertyValidator.
We already tried to implement IConfigurationPropertyValidator on the same class of our scheduled task; citing:
If outer class simply implements the configuration properties validator interface, then methods cannot use services [...]
Do you mean we could implement IConfigurationPropertyValidator instead of exteding AbstractConfigurationPropertyValidator on the inner class?

Have a look at our Secure User Property Store on GitHub which is also using a validator class
We saw the example you linked, but it's a stand-alone class. Instead, we are trying to use an inner class as configuration property validator in our existing class for a scheduled task.
Anyway, thank you Lukas for your answer.
Cheers.

Your answer


Register or to post your answer.