Bug 122261 - [typing] NullPointerException when performing "Correct indentation" and the first code line is a single-line comment
Summary: [typing] NullPointerException when performing "Correct indentation" and the f...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.1.1   Edit
Hardware: PC All
: P2 major (vote)
Target Milestone: 3.1.2   Edit
Assignee: Tom Hofmann CLA Friend
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-28 13:42 EST by Michael Schierl CLA Friend
Modified: 2006-01-10 05:33 EST (History)
1 user (show)

See Also:


Attachments
IndentAction.java.diff (659 bytes, patch)
2006-01-03 11:13 EST, Tom Hofmann CLA Friend
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Schierl CLA Friend 2005-12-28 13:42:32 EST
To reproduce: Create a java file that has a single line comment as its very first line. For example:

// this comment at the starting of the file is evil //
package indentbug;

public class Bug {
	/**
	 * To reproduce: Select the whole document and
	 * perform "Source->Correct indentation".
	 * (i. e. Ctrl+A, Ctrl+I)
	 */
}

When reindenting it, the following exception occurs:

!SESSION 2005-12-28 19:42:55.216 -----------------------------------------------
eclipse.buildId=M20050929-0840
java.version=1.5.0_05
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=de_DE
Command-line arguments:  -os win32 -ws win32 -arch x86

!ENTRY org.eclipse.ui 4 4 2005-12-28 19:43:05.391
!MESSAGE "Indent Line" did not complete normally.  Please see the log for more information.

!ENTRY org.eclipse.ui 4 0 2005-12-28 19:43:05.391
!MESSAGE java.lang.NullPointerException
!STACK 0
java.lang.NullPointerException
	at org.eclipse.jdt.internal.ui.actions.IndentAction.indentLine(IndentAction.java:243)
	at org.eclipse.jdt.internal.ui.actions.IndentAction.access$2(IndentAction.java:219)
	at org.eclipse.jdt.internal.ui.actions.IndentAction$1.run(IndentAction.java:141)
	at org.eclipse.jdt.internal.ui.actions.IndentAction.run(IndentAction.java:182)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:996)
	at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:182)
	at org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:108)
	at org.eclipse.core.commands.Command.execute(Command.java:311)
	at org.eclipse.core.commands.ParameterizedCommand.execute(ParameterizedCommand.java:396)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:459)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:781)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:828)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:550)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:493)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:117)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:917)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:842)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:867)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:852)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:880)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:876)
	at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1190)
	at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:3135)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:3038)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:3706)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1656)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2711)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1699)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1663)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:367)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143)
	at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:103)
	at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:226)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:376)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:163)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.core.launcher.Main.invokeFramework(Main.java:334)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:278)
	at org.eclipse.core.launcher.Main.run(Main.java:973)
	at org.eclipse.core.launcher.Main.main(Main.java:948)
Comment 1 Dani Megert CLA Friend 2006-01-02 09:39:49 EST
Happens in 3.1.1 and I20051220-0800.
Comment 2 Tom Hofmann CLA Friend 2006-01-03 11:13:07 EST
Created attachment 32414 [details]
IndentAction.java.diff

Patch against R1.35 of IndentAction.java. This only fixed the problem, but does not backport the tests added for 3.2.
Comment 3 Tom Hofmann CLA Friend 2006-01-03 11:13:55 EST
Fixed in HEAD > 20060103; also added regression tests.
Comment 4 Dani Megert CLA Friend 2006-01-03 12:07:25 EST
Fix reviewed and applied to R3_1_maintenance.
Comment 5 Markus Keller CLA Friend 2006-01-10 05:33:25 EST
Verified in M20060109-1200 and I20060105-0800.