Hi Alain, Is it possible that someone has a reference to a BaValidationManagerExt service instance that they aren’t releasing after ungetting it (or that they’re holding onto after it has been unregistered)? It might be an SCR bug, but it’s more likely to be some code holding onto a component instance that it shouldn’t.
Best Regards, Tim > On 29 Feb 2020, at 13:29, Alain Picard via osgi-dev <osgi-dev@mail.osgi.org> > wrote: > > Hi > > I am having a very intermittent issue with getService on a prototype > component. This is called hundreds of times and I put a breakpoint a few > weeks ago and have now gotten the error. > > I have this class: > @Component(scope=ServiceScope.PROTOTYPE, > property= org.osgi.framework.Constants.SERVICE_RANKING + ":Integer=10" > ) > public final class BaValidationManagerExt implements ValidationManagerExt { > private final Logger log = LoggerFactory.getLogger(getClass()); > > @Reference(scope = ReferenceScope.PROTOTYPE_REQUIRED) > private ComponentServiceObjects<Validator> validatorFactory; > > @Activate > private void activate() { > log.trace("Activating {}/{}", getClass(), System.identityHashCode(this)); > //$NON-NLS-1$ > } > > @Deactivate > private void deactivate() { > log.trace("Deactivating {}/{}", getClass(), System.identityHashCode(this)); > //$NON-NLS-1$ > } > .... > @Override > public Diagnostic getDiagnosticForEObject(EObject eObj) { > log.trace("Getting diagnostic for {}", eObj); //$NON-NLS-1$ > Validator validator = validatorFactory.getService(); > > if (validator != null) { > try { > return validator.runValidation(false, Collections.singletonMap(eObj, new > HashSet<>()), > new NullProgressMonitor()).getB(); > } > finally { > validatorFactory.ungetService(validator); > } > } > else { > log.error("Validator Service not found for {}", eObj, new Throwable()); > //$NON-NLS-1$ > return Diagnostic.CANCEL_INSTANCE; > } > } > } > > and the validator: > @Component( > scope = ServiceScope.PROTOTYPE, > property= org.osgi.framework.Constants.SERVICE_RANKING + ":Integer=10" > ) > public final class BaValidator implements Validator { > private final Logger log = LoggerFactory.getLogger(getClass()); > > private Map<EObject, Set<EObject>> elementsToValidate; > private Set<EObject> validated = Sets.newHashSet(); > private boolean batch; > > private EditingDomain domain; > private AdapterFactory adapterFactory; > > @Reference > private volatile List<ValidationProvider> validationProviders; //NOSONAR as > per OSGi 112.3.9.1 > > @Reference > private ValidationUtils validationUtils; > > @Activate > private void activate() { > log.trace("Activating {}/{}", getClass(), System.identityHashCode(this)); > //$NON-NLS-1$ > } > > @Deactivate > private void deactivate() { > log.trace("Deactivating {}/{}", getClass(), System.identityHashCode(this)); > //$NON-NLS-1$ > } > ... > } > > The error is on the highlighted line, which happens since getService returns > null. > > As can be seen here, ValidatorFactory serviceObjects is null which seems to > be what makes it return null: > ComponentServiceObjectsImpl [instances=[], serviceObjects=null, > deactivated=false, hashCode=301166435] > > I am not seeing any special in the logs (tracing is on). Just before I see a > number of successful call to the same code with the last one being: > just before in the logs: > 08:00:45.854 [Worker-1: Create Diagram] TRACE c.c.i.v.b.p.BaValidator - > Activating class > com.castortech.iris.validation.ba.provider.BaValidator/1297753057 > 08:00:45.857 [Worker-1: Create Diagram] TRACE c.c.i.v.b.p.BaValidator - > Notify 4 listeners with diagnostics ([Diagnostic OK > source=com.castortech.iris.ba.validation code=0 > data=[RadialDiagramImpl{[cdoID->6558b1f9-dbcf-4e9d-b7b8-73779b5ada8f] > 08:00:45.858 [Worker-1: Create Diagram] TRACE c.c.i.v.b.p.BaValidator - > Deactivating class > com.castortech.iris.validation.ba.provider.BaValidator/1297753057 > > > Has anyone seen this before or can provide some pointers to address and/or > debug this. > > Thanks > Alain > > _______________________________________________ > OSGi Developer Mail List > osgi-dev@mail.osgi.org > https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________ OSGi Developer Mail List osgi-dev@mail.osgi.org https://mail.osgi.org/mailman/listinfo/osgi-dev