Skip to main content

Why assertServiceContextNotDestroyed() is needed in ServiceContextImpl.removeListener(ServiceContextListener listner)?

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2011-05-17

This is regarding the Issue Tracker OCAP_RI-450.
As per the fix mentioned in the IT-OCAP_RI-450, the ProgramMonitor.updateServiceContext(ServiceContextExt sc) has to call m_serviceContext.removeListener(this) to remove previously added listener when the sc is null. But this call won't remove the previously added Listener as the IllegalStateException is thrown from the AssertServiceContextNotDestroyed. This is because the currentState (of is updated with the STATE_DESTROYED when the service context is destroyed(sc == null).
What are the advantages of having assertServiceContextNotDestroyed in ServiceContextImpl.removeListener(ServiceContextListener listener)? Does it protect the RI from any weird behavior?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-02-02

An IllegalStateException is thrown in order to comply with the JavaDoc contract for the method, which explicitly states an IllegalStateException is to be thrown when removeListener is called and the ServiceContext is in the DESTROYED state.
* Unsubscribes a listener from receiving events related to this
* <code>ServiceContext</code>. If the specified listener is not currently
* subscribed, no action is performed.
* @param listener
* The <code>ServiceContextListener</code> to unsubscribe.
* @throws IllegalStateException
* If the <code>ServiceContext</code> has been destroyed.
public void removeListener(ServiceContextListener listener);