[
https://issues.apache.org/jira/browse/FELIX-4325?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13827493#comment-13827493
]
Guillaume Nodet commented on FELIX-4325:
----------------------------------------
Proposed patch to implement the double-check-locking pattern to close the gap.
The use of this pattern is valid because the 3 properties checked are all
flagged as volatile.
{code}
diff --git
a/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
b/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.
index dacad1b..a3322bd 100644
---
a/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
+++
b/scr/src/main/java/org/apache/felix/scr/impl/manager/AbstractComponentManager.java
@@ -807,6 +807,24 @@ public abstract class AbstractComponentManager<S>
implements Component, SimpleLo
obtainActivationReadLock( "activateInternal" );
try
{
+ // Double check conditions now that we have obtained the lock
+ if ( m_disposed )
+ {
+ log( LogService.LOG_DEBUG, "ActivateInternal: disposed",
+ null );
+ return;
+ }
+ if ( m_activated ) {
+ log( LogService.LOG_DEBUG, "ActivateInternal: already
activated",
+ null );
+ return;
+ }
+ if ( !isEnabled() )
+ {
+ log( LogService.LOG_DEBUG, "Component is not enabled; not
activating component",
+ null );
+ return;
+ }
// Before creating the implementation object, we are going to
// test if all the mandatory dependencies are satisfied
if ( !verifyDependencyManagers() )
{code}
> [DS] Synchronization issue when activating component
> ----------------------------------------------------
>
> Key: FELIX-4325
> URL: https://issues.apache.org/jira/browse/FELIX-4325
> Project: Felix
> Issue Type: Bug
> Components: Declarative Services (SCR)
> Affects Versions: scr-1.8.0
> Reporter: Guillaume Nodet
> Assignee: Guillaume Nodet
> Fix For: scr-1.8.2
>
>
> When activating a component, the AbstractComponentManager#activateInternal
> method checks some properties, then grab the lock and actually activate the
> component, leaving a gap between the check and the lock being acquired, which
> can result in the component being deactivated in the mean time, ultimately
> leading to NPE because m_tracker has been nulled.
--
This message was sent by Atlassian JIRA
(v6.1#6144)