Eclipse (SWT) throws an NPE in TaskItem on MacOS

Eclipse (SWT) throws an NPE in TaskItem on MacOS

I was struggling to track down an NPE in the Yoxos Launcher that only happened on MacOS.  To help others avoid this, I thought I would share the problem (and solution). The stack trace was as follows:

java.lang.NullPointerException
        at org.eclipse.swt.widgets.TaskItem.updateImage(TaskItem.java:420)
        at org.eclipse.swt.widgets.TaskItem.setProgress(TaskItem.java:348)
        at org.eclipse.ui.internal.Workbench$TaskBarDelegatingProgressMontior.handleTaskBarProgressUpdated(Workbench.java:327)
        at org.eclipse.ui.internal.Workbench$TaskBarDelegatingProgressMontior.worked(Workbench.java:269)
        at org.eclipse.ui.internal.Workbench$StartupProgressBundleListener.bundleChanged(Workbench.java:421)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:847)
        at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
        at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
        at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1569)
        at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1505)
        at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1500)
        at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:391)
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
        at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
        at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:263)
        at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
        at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:469)
        at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
        at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:464)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
        at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

It turns out that I had an improperly configured Doc Icon in my .product file. When PDE/Build generates the product, the DocIcon is configured in the eclipse.ini file as follows:

-Xdock:icon=../Resources/YoxosLauncher.icns

If this doesn’t point to a proper icon, you will get the NPE.  Bug 320089 covers some of this too.