You can't simply cast here (I learned this the hard way; the framework can return just about anthing here). Check the returned object for instanceof IStructuredSelection and simply return null otherwise.