[ 
https://issues.apache.org/jira/browse/FELIX-6845?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18091122#comment-18091122
 ] 

Apoorv Rastogi commented on FELIX-6845:
---------------------------------------

*Root cause:* Race condition during service unregistration, a 
ServiceEvent.MODIFIED can be dispatched to ServiceListeners (including Felix's 
internal Log) after the registering bundle has already been unregistered.

*Fix:* Add a null check on the bundle reference in Log.serviceChanged() and 
return early if null, silently skipping the log entry for already-unregistered 
services.

*PR:* https://github.com/apache/felix-dev/pull/521

> NullPointerException in Log.serviceChanged() when 
> ServiceReference.getBundle() returns null
> -------------------------------------------------------------------------------------------
>
>                 Key: FELIX-6845
>                 URL: https://issues.apache.org/jira/browse/FELIX-6845
>             Project: Felix
>          Issue Type: Bug
>          Components: Log Service
>            Reporter: Ankur Singla
>            Priority: Major
>
> [https://github.com/apache/felix-dev/blob/master/log/src/main/java/org/apache/felix/log/Log.java#L326]
> *Description:*
> Log.serviceChanged() throws a NullPointerException when 
> ServiceReference.getBundle() returns null during service event processing.
> Per the OSGi spec, ServiceReference.getBundle() returns null when the 
> registering bundle has already been unregistered. This is a known race 
> condition during service unregistration, but the Felix log layer does not 
> guard against it.
>  *Stack trace:*
> {code:xml}
>  java.lang.NullPointerException: Cannot invoke 
> "org.osgi.framework.Bundle.getSymbolicName()"
>  because the return value of 
> "org.osgi.framework.ServiceReference.getBundle()" is null
>    at org.apache.felix.log.Log.serviceChanged(Log.java:326)
>    at 
> org.apache.felix.framework.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:990)
>    at 
> org.apache.felix.framework.EventDispatcher.fireEventImmediately(EventDispatcher.java:838)
>    at 
> org.apache.felix.framework.EventDispatcher.fireServiceEvent(EventDispatcher.java:545)
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to