Bug 40012 [preferences][templates] NPE in EditTemplateDialog
1. Open preference - java - code templates - constructor comments 2. Edit the comment template: Press CTRL + SPACE, choose $date 3. press CTRL + Z (undo) viewer.addTextListener(new ITextListener() { public void textChanged(TextEvent event) { doSourceChanged(event.getDocumentEvent().getDocument()); <- NPE here } }); java.lang.NullPointerException at org.eclipse.jdt.internal.ui.preferences.EditTemplateDialog$3.textChanged(EditTemplateDialog.java:464) at org.eclipse.jface.text.TextViewer.updateTextListeners(TextViewer.java:2146) at org.eclipse.jface.text.TextViewer.fireRedrawChanged(TextViewer.java:4055) at org.eclipse.jface.text.TextViewer.enabledRedrawing(TextViewer.java:4109) at org.eclipse.jface.text.TextViewer.setRedraw(TextViewer.java:4161) at org.eclipse.jface.text.DefaultUndoManager$CompoundTextCommand.undo(DefaultUndoManager.java:235) at org.eclipse.jface.text.DefaultUndoManager.internalUndo(DefaultUndoManager.java:529) at org.eclipse.jface.text.DefaultUndoManager.undo(DefaultUndoManager.java:807) at org.eclipse.jface.text.TextViewer.doOperation(TextViewer.java:3198) at org.eclipse.jface.text.source.SourceViewer.doOperation(SourceViewer.java:505) at org.eclipse.jdt.internal.ui.preferences.EditTemplateDialog.handleVerifyKeyPressed(EditTemplateDialog.java:524) at org.eclipse.jdt.internal.ui.preferences.EditTemplateDialog.access$1(EditTemplateDialog.java:509) at org.eclipse.jdt.internal.ui.preferences.EditTemplateDialog$5.verifyKey(EditTemplateDialog.java:477) at org.eclipse.jface.text.TextViewer$VerifyKeyListenersManager.verifyKey(TextViewer.java:372) at org.eclipse.swt.custom.StyledTextListener.handleEvent(StyledTextListener.java:55) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:848) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:872) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:857) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:665) at org.eclipse.swt.custom.StyledText.handleKeyDown(StyledText.java:5201) at org.eclipse.swt.custom.StyledText$8.handleEvent(StyledText.java:4950) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:848) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:872) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:857) at org.eclipse.swt.widgets.Control.sendKeyEvent(Control.java:1637) at org.eclipse.swt.widgets.Control.sendKeyEvent(Control.java:1633) at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:2945) at org.eclipse.swt.widgets.Control.windowProc(Control.java:2824) at org.eclipse.swt.widgets.Display.windowProc(Display.java:2566) at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method) at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1334) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1745) at org.eclipse.jface.window.Window.runEventLoop(Window.java:583) at org.eclipse.jface.window.Window.open(Window.java:563) at org.eclipse.jdt.internal.ui.preferences.CodeTemplateBlock.edit(CodeTemplateBlock.java:346) at org.eclipse.jdt.internal.ui.preferences.CodeTemplateBlock.doButtonPressed(CodeTemplateBlock.java:333) at org.eclipse.jdt.internal.ui.preferences.CodeTemplateBlock$CodeTemplateAdapter.doubleClicked(CodeTemplateBlock.java:81) at org.eclipse.jdt.internal.ui.wizards.dialogfields.TreeListDialogField.doDoubleClick(TreeListDialogField.java:890) at org.eclipse.jdt.internal.ui.wizards.dialogfields.TreeListDialogField$TreeViewerAdapter.doubleClick(TreeListDialogField.java:876) at org.eclipse.jface.viewers.StructuredViewer$1.run(StructuredViewer.java:367) at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1015) at org.eclipse.core.runtime.Platform.run(Platform.java:420) at org.eclipse.jface.viewers.StructuredViewer.fireDoubleClick(StructuredViewer.java:365) at org.eclipse.jface.viewers.StructuredViewer.handleDoubleSelect(StructuredViewer.java:584) at org.eclipse.jface.viewers.StructuredViewer$4.widgetDefaultSelected(StructuredViewer.java:679) at org.eclipse.jface.util.OpenStrategy.fireDefaultSelectionEvent(OpenStrategy.java:187) at org.eclipse.jface.util.OpenStrategy.access$0(OpenStrategy.java:184) at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:231) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:848) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2041) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1747) at org.eclipse.jface.window.Window.runEventLoop(Window.java:583) at org.eclipse.jface.window.Window.open(Window.java:563) at org.eclipse.ui.internal.OpenPreferencesAction.run(OpenPreferencesAction.java:53) at org.eclipse.jface.action.Action.runWithEvent(Action.java:842) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:542) at org.eclipse.jface.action.ActionContributionItem.access$4(ActionContributionItem.java:496) at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:468) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:848) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2041) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1747) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1383) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1366) at org.eclipse.core.internal.boot.InternalBootLoader.run(InternalBootLoader.java:858) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.core.launcher.Main.basicRun(Main.java:291) at org.eclipse.core.launcher.Main.run(Main.java:747) at org.eclipse.core.launcher.Main.main(Main.java:583)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/EditTemplateDialog.java
action= new TextViewerAction(fPatternEditor, SourceViewer.SELECT_ALL);
		action.setText(TemplateMessages.getString("EditTemplateDialog.select.all")); 
		fGlobalActions.put(ITextEditorActionConstants.SELECT_ALL, action);
		action= new TextViewerAction(fPatternEditor, SourceViewer.CONTENTASSIST_PROPOSALS);
		action.setText(TemplateMessages.getString("EditTemplateDialog.content.assist")); 
		fGlobalActions.put("ContentAssistProposal", action); 
		fSelectionActions.add(ITextEditorActionConstants.CUT);
		fSelectionActions.add(ITextEditorActionConstants.COPY);
		fSelectionActions.add(ITextEditorActionConstants.PASTE);
		
		
		MenuManager manager= new MenuManager(null, null);
		manager.setRemoveAllWhenShown(true);
		manager.addMenuListener(new IMenuListener() {
			public void menuAboutToShow(IMenuManager mgr) {
				fillContextMenu(mgr);
			}
		});
		StyledText text= fPatternEditor.getTextWidget();		
		Menu menu= manager.createContextMenu(text);
		text.setMenu(menu);
	}
	private void fillContextMenu(IMenuManager menu) {
		menu.add(new GroupMarker(ITextEditorActionConstants.GROUP_UNDO));
		menu.appendToGroup(ITextEditorActionConstants.GROUP_UNDO, (IAction) fGlobalActions.get(ITextEditorActionConstants.UNDO));
		
		menu.add(new Separator(ITextEditorActionConstants.GROUP_EDIT));		
		menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, (IAction) fGlobalActions.get(ITextEditorActionConstants.CUT));
		menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, (IAction) fGlobalActions.get(ITextEditorActionConstants.COPY));
		menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, (IAction) fGlobalActions.get(ITextEditorActionConstants.PASTE));