Community
Participate
Working Groups
Created attachment 95819 [details] Simple patch that makes getServices() null tolerant. Today I saw an NPE thrown from the Equinox Console... Exception in thread "OSGi Console" java.lang.NullPointerException at org.eclipse.osgi.framework.internal.core.FrameworkConsole.getServices(FrameworkConsole.java:368) at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:297) at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(FrameworkConsole.java:285) at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:221) This is probably rather rare, but is still possible. I was using org.eclipse.osgi_3.3.2.R33x_v20080105.jar. public Object[] getServices() { ServiceReference[] serviceRefs = cptracker.getServiceReferences(); Util.dsort(serviceRefs, 0, serviceRefs.length); // Line 368 ... } The problem was that serviceRefs was null. The ServiceTracker's getServiceReferences() method can return null. The attached path is for the latest version of the code, and it simply returns null if serviceRefs is null: public Object[] getServices() { ServiceReference[] serviceRefs = cptracker.getServiceReferences(); if (serviceRefs == null) return null; Util.dsort(serviceRefs, 0, serviceRefs.length); ... }
Thanks Simon. I slightly modified the patch to return new Object[0]. If null was returned then we would just NPE later in FrameworkCommandInterpreter.docommand.
Ah, I was just following the Javadoc, rather than checking for callers. Please update the Javadoc for the FrameworkConsole method getServices(), which today claims that null can be returned. * @return Array of service objects or <tt>null</tt> if no service * are being tracked. Thanks you Tom.
I updated the javadoc. Thanks Simon.
It's always a pleasure, Tom. Thank you.
This got fixed for M7.