You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:28:27 UTC
[sling-org-apache-sling-discovery-oak] 06/32: SLING-5382 : avoid
NPE when PropertyProviders are bind/unbind/changed before activate
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.discovery.oak-1.2.10
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-discovery-oak.git
commit 7bf9afb0128eb9ad439c02ae3a3d93bec427e3cf
Author: Stefan Egli <st...@apache.org>
AuthorDate: Wed Jan 27 13:21:26 2016 +0000
SLING-5382 : avoid NPE when PropertyProviders are bind/unbind/changed before activate
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/discovery/oak@1727036 13f79535-47bb-0310-9956-ffa450edef68
---
.../sling/discovery/oak/OakDiscoveryService.java | 38 ++++++++++++++++------
1 file changed, 28 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/apache/sling/discovery/oak/OakDiscoveryService.java b/src/main/java/org/apache/sling/discovery/oak/OakDiscoveryService.java
index 2beab3b..bdbbd97 100644
--- a/src/main/java/org/apache/sling/discovery/oak/OakDiscoveryService.java
+++ b/src/main/java/org/apache/sling/discovery/oak/OakDiscoveryService.java
@@ -107,7 +107,7 @@ public class OakDiscoveryService extends BaseDiscoveryService {
* whether or not this service is activated - necessary to avoid sending
* events to discovery awares before activate is done
**/
- private boolean activated = false;
+ private volatile boolean activated = false;
@Reference
private ResourceResolverFactory resourceResolverFactory;
@@ -400,7 +400,9 @@ public class OakDiscoveryService extends BaseDiscoveryService {
final ProviderInfo info = new ProviderInfo(propertyProvider, props);
this.providerInfos.add(info);
Collections.sort(this.providerInfos);
- this.doUpdateProperties();
+ if (activated) {
+ this.doUpdateProperties();
+ }
checkForTopologyChange();
}
@@ -439,7 +441,9 @@ public class OakDiscoveryService extends BaseDiscoveryService {
final ProviderInfo info = new ProviderInfo(propertyProvider, props);
if ( this.providerInfos.remove(info) && update ) {
- this.doUpdateProperties();
+ if (activated) {
+ this.doUpdateProperties();
+ }
this.checkForTopologyChange();
}
}
@@ -454,9 +458,19 @@ public class OakDiscoveryService extends BaseDiscoveryService {
* @see Config#getClusterInstancesPath()
*/
private void doUpdateProperties() {
- if (resourceResolverFactory == null) {
+ // SLING-5382 : the caller must ensure that this method
+ // is not invoked after deactivation or before activation.
+ // so this method doesn't have to do any further synchronization.
+ // what we do nevertheless is a paranoia way of checking if
+ // all variables are available and do a NOOP if that's not the case.
+ final ResourceResolverFactory rrf = resourceResolverFactory;
+ final Config c = config;
+ final String sid = slingId;
+ if (rrf == null || c == null || sid == null) {
// cannot update the properties then..
- logger.debug("doUpdateProperties: too early to update the properties. resourceResolverFactory not yet set.");
+ logger.debug("doUpdateProperties: too early to update the properties. "
+ + "resourceResolverFactory ({}), config ({}) or slingId ({}) not yet set.",
+ new Object[] {rrf, c, sid});
return;
} else {
logger.debug("doUpdateProperties: updating properties now..");
@@ -470,14 +484,14 @@ public class OakDiscoveryService extends BaseDiscoveryService {
ResourceResolver resourceResolver = null;
try {
- resourceResolver = resourceResolverFactory
+ resourceResolver = rrf
.getAdministrativeResourceResolver(null);
Resource myInstance = ResourceHelper
.getOrCreateResource(
resourceResolver,
- config.getClusterInstancesPath()
- + "/" + slingId + "/properties");
+ c.getClusterInstancesPath()
+ + "/" + sid + "/properties");
// SLING-2879 - revert/refresh resourceResolver here to work
// around a potential issue with jackrabbit in a clustered environment
resourceResolver.revert();
@@ -541,8 +555,12 @@ public class OakDiscoveryService extends BaseDiscoveryService {
*/
public void updateProperties() {
synchronized (lock) {
- logger.debug("updateProperties: calling doUpdateProperties.");
- doUpdateProperties();
+ if (!activated) {
+ logger.debug("updateProperties: not yet activated, not calling doUpdateProperties this time.");
+ } else {
+ logger.debug("updateProperties: calling doUpdateProperties.");
+ doUpdateProperties();
+ }
logger.debug("updateProperties: calling handlePotentialTopologyChange.");
checkForTopologyChange();
logger.debug("updateProperties: done.");
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.