Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 326033

Summary: ClassCastException handling of r_osgi event handler topics
Product: [RT] ECF Reporter: Wim Jongman <wim.jongman>
Component: ecf.remoteservicesAssignee: Wim Jongman <wim.jongman>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: bugs.eclipse.org
Version: 3.3.0   
Target Milestone: 3.4.0   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
mylyn/context/zip none

Description Wim Jongman CLA 2010-09-23 07:19:13 EDT
Hi,

In the /ch.ethz.iks.r_osgi.remote/src/main/java/ch/ethz/iks/r_osgi/impl/RemoteOSGiServiceImpl.setupTrackers() there is an assumption that all event handlers have assigned a topic of String[]. According to OSGi specs the topic of interests can be a String or a String[]

This leads to r_osgi crashing. 

I propose the following change which has been tested by us:

public Object addingService(
	final ServiceReference reference) {
	final String[] theTopics;
	Object topics = reference.getProperty(EventConstants.EVENT_TOPIC);
	if (topics instanceof String)
		theTopics = new String[] { (String) topics };
		 else
		theTopics = 
             (String[]) reference.getProperty(EventConstants.EVENT_TOPIC);

=================================
STACKTRACE (line numbers could be slightly different from the currennt impl)
=================================


!ENTRY org.eclipse.osgi 4 0 2010-09-23 13:16:37.555
!MESSAGE An unexpected runtime error has occurred.
!STACK 0
java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.String;
	at ch.ethz.iks.r_osgi.impl.RemoteOSGiServiceImpl$1.addingService(RemoteOSGiServiceImpl.java:1130)
	at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:896)
	at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:261)
	at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:233)
	at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:840)
	at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:104)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:933)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227)
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:149)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:756)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:711)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:130)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:206)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:507)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:525)
	at com.remainsoftware.gravity.event.dispatcher.Activator.start(Activator.java:29)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:783)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:774)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:755)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:370)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:374)
	at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1067)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:561)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:546)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:459)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:440)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227)
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:337)
Comment 1 Markus Kuppe CLA 2010-09-23 09:09:27 EDT
ch.ethz.iks.r_osgi.impl.RemoteOSGiServiceImpl.setupTrackers(...).new ServiceTrackerCustomizer() {...}.modifiedService(ServiceReference, Object) also explicitly casts to String[]. Does it need the instanceof check too?
Comment 2 Wim Jongman CLA 2010-09-23 12:38:13 EDT
(In reply to comment #1)
> ch.ethz.iks.r_osgi.impl.RemoteOSGiServiceImpl.setupTrackers(...).new
> ServiceTrackerCustomizer() {...}.modifiedService(ServiceReference, Object) also
> explicitly casts to String[]. Does it need the instanceof check too?

Yes.
Comment 3 Markus Kuppe CLA 2010-09-24 03:23:14 EDT
+1 for the addition. Are you going to do it Wim?
Comment 4 Wim Jongman CLA 2010-09-24 05:45:56 EDT
Hi,

I have solved the issues but now I try to integrate this into the abstract remote testing framework. Excellent work by the way. 

I now have a specific service that is not handled well (eventhandler). I would like to add a test case for this specific service but the only thing that the abstract testing seems to handle is the iconcat service.

However, I think the framework can be extended quite easy to enable more service scenarios instead of this single iconcat service. 

Should I consider a change in the testing framework or move around this and test this bug in another way?
Comment 5 Markus Kuppe CLA 2010-09-24 05:48:17 EDT
(In reply to comment #4)
> Hi,
> 
> I have solved the issues but now I try to integrate this into the abstract
> remote testing framework. Excellent work by the way. 
> 
> I now have a specific service that is not handled well (eventhandler). I would
> like to add a test case for this specific service but the only thing that the
> abstract testing seems to handle is the iconcat service.
> 
> However, I think the framework can be extended quite easy to enable more
> service scenarios instead of this single iconcat service. 
> 
> Should I consider a change in the testing framework or move around this and
> test this bug in another way?

+1 for an enhancement to the testing framework. Maybe we want to track this in a separate bug though. :)
Comment 6 Wim Jongman CLA 2010-09-24 18:43:34 EDT
Fix checked into HEAD

I tried to add this to the test but even with r_osgi throwing CCE's there is nothing I can do to make the test fail. org.eclipse.osgi.framework.internal.core.BundleContextImpl prints a stack trace and swallows the exception. The remote service (EventHandler) is registered.
Comment 7 Wim Jongman CLA 2010-09-24 18:43:47 EDT
Created attachment 179552 [details]
mylyn/context/zip