Community
Participate
Working Groups
While trying to extract the code shown in code.txt attachment to a method: !ENTRY org.eclipse.ui 4 0 Jun 05, 2002 16:41:53.336 !MESSAGE java.lang.NullPointerException !STACK 0 java.lang.NullPointerException at org.eclipse.jdt.internal.corext.util.Strings.computeIndent (Strings.java:128) at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.computeIndent (CodeFormatterUtil.java:43) at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.createIndentString (CodeFormatterUtil.java:66) at org.eclipse.jdt.internal.corext.codemanipulation.MethodBlock.fill (MethodBlock.java:52) at org.eclipse.jdt.internal.corext.codemanipulation.CodeBlockEdit.createText (CodeBlockEdit.java:123) at org.eclipse.jdt.internal.corext.codemanipulation.CodeBlockEdit.perform (CodeBlockEdit.java:94) at org.eclipse.jdt.internal.corext.textmanipulation.TextEditNode.performDo (TextEditNode.java:444) at org.eclipse.jdt.internal.corext.textmanipulation.TextEditNode.performDo (TextEditNode.java:438) at org.eclipse.jdt.internal.corext.textmanipulation.TextEditNode$RootNode.performDo (TextEditNode.java:49) at org.eclipse.jdt.internal.corext.textmanipulation.TextBufferEditor.performEdits (TextBufferEditor.java:173) at org.eclipse.jdt.internal.corext.refactoring.changes.TextChange.getPreviewTextBuf fer(TextChange.java:187) at org.eclipse.jdt.internal.corext.refactoring.changes.TextChange.getPreviewContent (TextChange.java:177) at org.eclipse.jdt.internal.ui.refactoring.PreviewWizardPage.getCompareInput (PreviewWizardPage.java:236) at org.eclipse.jdt.internal.ui.refactoring.PreviewWizardPage.getPreviewer (PreviewWizardPage.java:298) at org.eclipse.jdt.internal.ui.refactoring.PreviewWizardPage.showPreview (PreviewWizardPage.java:429) at org.eclipse.jdt.internal.ui.refactoring.PreviewWizardPage.access$2 (PreviewWizardPage.java:427) at org.eclipse.jdt.internal.ui.refactoring.PreviewWizardPage$2.selectionChanged (PreviewWizardPage.java:418) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged (Viewer.java:147) at org.eclipse.jface.viewers.StructuredViewer.updateSelection (StructuredViewer.java:1153) at org.eclipse.jface.viewers.StructuredViewer.setSelection (StructuredViewer.java:903) at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:342) at org.eclipse.jdt.internal.ui.refactoring.PreviewWizardPage.setVisible (PreviewWizardPage.java:383) at org.eclipse.jface.wizard.WizardDialog.showPage(WizardDialog.java:888) at org.eclipse.jface.wizard.WizardDialog.nextPressed (WizardDialog.java:653) at org.eclipse.jface.wizard.WizardDialog.buttonPressed (WizardDialog.java:308) at org.eclipse.jface.dialogs.Dialog$1.widgetSelected(Dialog.java:398) at org.eclipse.swt.widgets.TypedListener.handleEvent (TypedListener.java:85) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:75) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:825) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1527) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1289) at org.eclipse.jface.window.Window.runEventLoop(Window.java:558) at org.eclipse.jface.window.Window.open(Window.java:538) at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate (RefactoringStarter.java:79) at org.eclipse.jdt.ui.actions.ExtractMethodAction.run (ExtractMethodAction.java:47) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun (SelectionDispatchAction.java:180) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run (SelectionDispatchAction.java:156) at org.eclipse.jface.action.Action.runWithEvent(Action.java:749) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection (ActionContributionItem.java:407) at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent (ActionContributionItem.java:361) at org.eclipse.jface.action.ActionContributionItem.access$0 (ActionContributionItem.java:352) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent (ActionContributionItem.java:47) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:75) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:825) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1527) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1289) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1177) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1160) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:739) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:462) at java.lang.reflect.Method.invoke(Native Method) at org.eclipse.core.launcher.Main.basicRun(Main.java:244) at org.eclipse.core.launcher.Main.run(Main.java:693) at org.eclipse.core.launcher.Main.main(Main.java:526)
Created attachment 1263 [details] code.txt
Till, what is the original context (file, project) for the code snippet
This should normally not happen. The problem is that the position returned from code formatter doesn't map to a valid position in the string anymore.
i saw the file too - positions were really out of synch (judging by what structured selection said) Till, you still have the file around?
sent the file to Dirk
This is a formatter problem. Here is the scenario I use: code to format: private void eee(String string, TextBufferEditor tbe, String lineDelimiter, IMember member, String source, IScanner scanner) throws JavaModelException, CoreException{ x(); } Formatter call: String formattedCode= formatter.format(codeToFormat, 0, positions, lineSeparator); positions is [165, 168] lineSeparator is ascii 10 The result is a string of length 183 put the returned positions are [184, 187]. So they lay outside the string which causes the NPE since I don't handle this case.
Note that codeToFormat is one string with line delimiters.
Added guard code and fixup code if the positions seem to be bogus.
Moving to JDT/Core since it is a formatter bug.
We did not change this code recently, it should have never work since day one.
The problem only occurs if there is a double split of the string. In your example, there is a split on the throws keyword and on the commas in the parameters list.
Dirk Baeumer says, over at bug 18997, that that bug is related to this one.
*** This bug has been marked as a duplicate of 18997 ***