cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Amichai Rothman (JIRA)" <>
Subject [jira] [Created] (DOSGI-171) service objects are never released (using ungetService)
Date Sun, 14 Apr 2013 10:16:16 GMT
Amichai Rothman created DOSGI-171:

             Summary: service objects are never released (using ungetService)
                 Key: DOSGI-171
             Project: CXF Distributed OSGi
          Issue Type: Bug
    Affects Versions: 1.4.0, 1.5
            Reporter: Amichai Rothman

The BundleContext.getService() spec/API states that for every time this method returns a service
object, it must later be released using BundleContext.ungetService(). Further, after ungetService
is called, all references to the service object should be removed (set to null) so that it
can be properly released.

Currently, there are many usages of getService in the code, but none of them release the reference
as required.

The recommendation seems to be to use service trackers where possible instead of directly
accessing the getService/ungetService APIs, since the ServiceTracker was created for this
exact purpose - to properly handle all the bookkeeping for service references. Alternatively,
in places in which a ServiceTracker is not appropriate and the services are used locally,
the getService call should be followed by a try-finally block which always ungets the service
when done as is standard practice with resource management. Finally, in places in which the
service access is not contained in a local method, and is stored in a field or passed around,
proper resource release should be performed (ungetService called and references nulled afterwards)
in an appropriate way for those cases (when closing or releasing the containing class instance,

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message