Source:
<code>public void createPartControl(Composite parent) { BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); this.logReaderServiceTracker = new ServiceTracker<LogReaderService, LogReaderService>(context, LogReaderService.class, null) { @Override public LogReaderService addingService(ServiceReference<LogReaderService> reference) { LogReaderService service = context.getService(reference); <START> service.addLogListener(LogView.this); <END> return service; } @Override public void removedService(ServiceReference<LogReaderService> reference, LogReaderService service) { service.removeLogListener(LogView.this); } }; this.logReaderServiceTracker.open(); Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.marginWidth = 0; layout.marginHeight = 0; composite.setLayout(layout); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); readLogFile(); createViewer(composite); getSite().setSelectionProvider(fFilteredTree.getViewer()); createActions(); fClipboard = new Clipboard(fTree.getDisplay()); fTree.setToolTipText(""); initializeViewerSorter(); makeHoverShell(); PlatformUI.getWorkbench().getHelpSystem().setHelp(fFilteredTree, IHelpContextIds.LOG_VIEW); getSite().getWorkbenchWindow().addPerspectiveListener(new IPerspectiveListener2() { @Override public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, IWorkbenchPartReference partRef, String changeId) { if (!(partRef instanceof IViewReference)) return; IWorkbenchPart part = partRef.getPart(false); if (part == null) { return; } if (part.equals(LogView.this)) { if (changeId.equals(IWorkbenchPage.CHANGE_VIEW_SHOW)) { if (!batchedEntries.isEmpty()) { pushBatchedEntries(); } batchEntries = false; } else if (changeId.equals(IWorkbenchPage.CHANGE_VIEW_HIDE)) { batchEntries = true; } } } @Override public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) { } @Override public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) { } }); }</code><technical_language>check for null returned reference</technical_language>

Target:
public void createPartControl(Composite parent) { BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); this.logReaderServiceTracker = new ServiceTracker<LogReaderService, LogReaderService>(context, LogReaderService.class, null) { @Override public LogReaderService addingService(ServiceReference<LogReaderService> reference) { LogReaderService service = context.getService(reference); if (service != null) { service.addLogListener(LogView.this); } return service; } @Override public void removedService(ServiceReference<LogReaderService> reference, LogReaderService service) { service.removeLogListener(LogView.this); } }; this.logReaderServiceTracker.open(); Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.horizontalSpacing = 0; layout.verticalSpacing = 0; layout.marginWidth = 0; layout.marginHeight = 0; composite.setLayout(layout); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); readLogFile(); createViewer(composite); getSite().setSelectionProvider(fFilteredTree.getViewer()); createActions(); fClipboard = new Clipboard(fTree.getDisplay()); fTree.setToolTipText(""); initializeViewerSorter(); makeHoverShell(); PlatformUI.getWorkbench().getHelpSystem().setHelp(fFilteredTree, IHelpContextIds.LOG_VIEW); getSite().getWorkbenchWindow().addPerspectiveListener(new IPerspectiveListener2() { @Override public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, IWorkbenchPartReference partRef, String changeId) { if (!(partRef instanceof IViewReference)) return; IWorkbenchPart part = partRef.getPart(false); if (part == null) { return; } if (part.equals(LogView.this)) { if (changeId.equals(IWorkbenchPage.CHANGE_VIEW_SHOW)) { if (!batchedEntries.isEmpty()) { pushBatchedEntries(); } batchEntries = false; } else if (changeId.equals(IWorkbenchPage.CHANGE_VIEW_HIDE)) { batchEntries = true; } } } @Override public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) { } @Override public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) { } }); }