Community
Participate
Working Groups
Created attachment 254939 [details] Screenshot Triggering the quick fix "Add throws declaration" fails due to IndexOutOfBoundsExcetion issued by the formatter. java.lang.IndexOutOfBoundsException: Index: 8, Size: 8 at java.util.ArrayList.rangeCheck(ArrayList.java:658) at java.util.ArrayList.get(ArrayList.java:431) at org.eclipse.jdt.internal.formatter.TokenManager.get(TokenManager.java:68) at org.eclipse.jdt.internal.formatter.TokenManager.findIndex(TokenManager.java:161) at org.eclipse.jdt.internal.formatter.TokenManager.firstIndexIn(TokenManager.java:188) at org.eclipse.jdt.internal.formatter.TokenManager.firstTokenIn(TokenManager.java:194) at org.eclipse.jdt.internal.formatter.SpacePreparator.visit(SpacePreparator.java:196) at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:611) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2782) at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:470) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.prepareSpaces(DefaultCodeFormatter.java:350) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.prepareFormattedCode(DefaultCodeFormatter.java:193) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:155) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:139) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteFormatter.formatString(ASTRewriteFormatter.java:246) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteFormatter.formatNode(ASTRewriteFormatter.java:376) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteFormatter.getFormattedResult(ASTRewriteFormatter.java:187) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.doTextInsert(ASTRewriteAnalyzer.java:1357) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer$ListRewriter.rewriteList(ASTRewriteAnalyzer.java:647) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer$ListRewriter.rewriteList(ASTRewriteAnalyzer.java:553) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.rewriteNodeList(ASTRewriteAnalyzer.java:1243) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.visit(ASTRewriteAnalyzer.java:2048) at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:611) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711) at org.eclipse.jdt.core.dom.rewrite.ASTRewrite.internalRewriteAST(ASTRewrite.java:302) at org.eclipse.jdt.core.dom.rewrite.ASTRewrite.rewriteAST(ASTRewrite.java:291) at org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal.addEdits(ASTRewriteCorrectionProposal.java:116) at org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal.createTextChange(CUCorrectionProposal.java:234) at org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal.createChange(CUCorrectionProposal.java:244) at org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal.getChange(ChangeCorrectionProposal.java:377) at org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal.performChange(ChangeCorrectionProposal.java:137) at org.eclipse.jdt.internal.ui.text.correction.proposals.LinkedCorrectionProposal.performChange(LinkedCorrectionProposal.java:150) at org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal.apply(CUCorrectionProposal.java:184) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:968) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertSelectedProposalWithMask(CompletionProposalPopup.java:914) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.verifyKey(CompletionProposalPopup.java:1358) at org.eclipse.jface.text.contentassist.ContentAssistant$InternalListener.verifyKey(ContentAssistant.java:814) at org.eclipse.jface.text.TextViewer$VerifyKeyListenersManager.verifyKey(TextViewer.java:493) at org.eclipse.swt.custom.StyledTextListener.handleEvent(StyledTextListener.java:66) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4230) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1491) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1514) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1499) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1299) at org.eclipse.swt.custom.StyledText.handleKeyDown(StyledText.java:5990) at org.eclipse.swt.custom.StyledText$7.handleEvent(StyledText.java:5682) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4230) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1491) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1514) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1499) at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1528) at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1524) at org.eclipse.swt.widgets.Canvas.sendKeyEvent(Canvas.java:496) at org.eclipse.swt.widgets.Control.doCommandBySelector(Control.java:1060) at org.eclipse.swt.widgets.Display.windowProc(Display.java:5784) at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method) at org.eclipse.swt.internal.cocoa.NSResponder.interpretKeyEvents(NSResponder.java:68) at org.eclipse.swt.widgets.Composite.keyDown(Composite.java:594) at org.eclipse.swt.widgets.Display.windowProc(Display.java:5694) at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method) at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:227) at org.eclipse.swt.widgets.Widget.windowSendEvent(Widget.java:2130) at org.eclipse.swt.widgets.Shell.windowSendEvent(Shell.java:2337) at org.eclipse.swt.widgets.Display.windowProc(Display.java:5756) at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method) at org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:5193) at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5342) at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method) at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:128) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3695) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018) at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:502) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608) at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
Oliver: Can you please provide a code snippet which is reproducible?
package example; import org.junit.Test; public class TestType { @Test public void testname() { Thread.sleep(1000); } }
Triggering a refactoring (I tried "Extract interface") consistently fails with an exception pointing to the same component, too. java.lang.reflect.InvocationTargetException at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:420) at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.run(RefactoringWizardDialog2.java:331) at org.eclipse.ltk.ui.refactoring.RefactoringWizard.internalPerformFinish(RefactoringWizard.java:637) at org.eclipse.ltk.ui.refactoring.UserInputWizardPage.performFinish(UserInputWizardPage.java:153) at org.eclipse.jdt.internal.ui.refactoring.ExtractInterfaceWizard$ExtractInterfaceInputPage.performFinish(ExtractInterfaceWizard.java:359) at org.eclipse.ltk.ui.refactoring.RefactoringWizard.performFinish(RefactoringWizard.java:710) at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.okPressed(RefactoringWizardDialog2.java:455) at org.eclipse.jface.dialogs.Dialog.buttonPressed(Dialog.java:466) at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:619) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4230) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1491) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1514) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1499) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1299) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4072) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3698) at org.eclipse.jface.window.Window.runEventLoop(Window.java:827) at org.eclipse.jface.window.Window.open(Window.java:803) at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation$1.run(RefactoringWizardOpenOperation.java:187) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70) at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:202) at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:122) at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate(RefactoringStarter.java:38) at org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter.startExtractInterfaceRefactoring(RefactoringExecutionStarter.java:290) at org.eclipse.jdt.ui.actions.ExtractInterfaceAction.run(ExtractInterfaceAction.java:147) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:279) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:251) at org.eclipse.jface.action.Action.runWithEvent(Action.java:473) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:595) at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:511) at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:420) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4230) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1491) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1514) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1499) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1299) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4072) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3698) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018) at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:502) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608) at org.eclipse.equinox.launcher.Main.run(Main.java:1515) Caused by: java.lang.IndexOutOfBoundsException: Index: 5, Size: 5 at java.util.ArrayList.rangeCheck(ArrayList.java:658) at java.util.ArrayList.get(ArrayList.java:431) at org.eclipse.jdt.internal.formatter.TokenManager.get(TokenManager.java:68) at org.eclipse.jdt.internal.formatter.TokenManager.findIndex(TokenManager.java:161) at org.eclipse.jdt.internal.formatter.TokenManager.firstIndexIn(TokenManager.java:188) at org.eclipse.jdt.internal.formatter.TokenManager.firstTokenIn(TokenManager.java:194) at org.eclipse.jdt.internal.formatter.SpacePreparator.visit(SpacePreparator.java:196) at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:611) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2782) at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:470) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.prepareSpaces(DefaultCodeFormatter.java:350) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.prepareFormattedCode(DefaultCodeFormatter.java:193) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:155) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:139) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteFormatter.formatString(ASTRewriteFormatter.java:246) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteFormatter.formatNode(ASTRewriteFormatter.java:376) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteFormatter.getFormattedResult(ASTRewriteFormatter.java:187) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.doTextInsert(ASTRewriteAnalyzer.java:1357) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer$ListRewriter.rewriteList(ASTRewriteAnalyzer.java:647) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer$ListRewriter.rewriteList(ASTRewriteAnalyzer.java:802) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.rewriteParagraphList(ASTRewriteAnalyzer.java:1175) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.visit(ASTRewriteAnalyzer.java:1811) at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:453) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.doVisit(ASTRewriteAnalyzer.java:408) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.voidVisitList(ASTRewriteAnalyzer.java:446) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.voidVisit(ASTRewriteAnalyzer.java:440) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.doVisitUnchangedChildren(ASTRewriteAnalyzer.java:453) at org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.visit(ASTRewriteAnalyzer.java:1673) at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:207) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711) at org.eclipse.jdt.core.dom.rewrite.ASTRewrite.internalRewriteAST(ASTRewrite.java:302) at org.eclipse.jdt.core.dom.rewrite.ASTRewrite.rewriteAST(ASTRewrite.java:233) at org.eclipse.jdt.internal.corext.refactoring.structure.constraints.SuperTypeRefactoringProcessor.createTypeDeclaration(SuperTypeRefactoringProcessor.java:294) at org.eclipse.jdt.internal.corext.refactoring.structure.constraints.SuperTypeRefactoringProcessor.createTypeSource(SuperTypeRefactoringProcessor.java:432) at org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor.createChangeManager(ExtractInterfaceProcessor.java:415) at org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor.checkFinalConditions(ExtractInterfaceProcessor.java:245) at org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring.checkFinalConditions(ProcessorBasedRefactoring.java:224) at org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:85) at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:121) at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:209) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2241) at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
(In reply to Oliver Gierke from comment #2) > package example; > > import org.junit.Test; > > public class TestType { > > @Test > public void testname() { > Thread.sleep(1000); > } > } Thanks for the snippet Oliver - however I don't get an error when I go for the quick fix and the code gets transformed to package example; import org.junit.Test; public class TestType { @Test public void testname() throws InterruptedException { Thread.sleep(1000); } } I am using Eclipse Mars Stable release. Using the quickfix under the Thread.sleep() .Do you see this error in the Mars release?
Yes. I am running STS 3.7.0 with the following specs Spring Tool Suite Version: 3.7.0.CI-B260 Build Id: 201506250849 Platform: Eclipse Mars (4.5.0) org.eclipse.jdt (3.11.0.v20150603-2000) I guess it might be related to the formatter configured as we're using customized formatter settings. I've tried turning off the save action to auto format but that didn't change anything. Is there a way for me to debug into TokenManager at runtime?
*** Bug 471758 has been marked as a duplicate of this bug. ***
(In reply to Oliver Gierke from comment #5) > Yes. I am running STS 3.7.0 with the following specs > > org.eclipse.jdt (3.11.0.v20150603-2000) > > I guess it might be related to the formatter configured as we're using > customized formatter settings. I've tried turning off the save action to > auto format but that didn't change anything. > Can you please attach the customized formatter settings in the bug?
Created attachment 255001 [details] Formatter Attached the formatter.
*** Bug 472018 has been marked as a duplicate of this bug. ***
Mateusz: Please take a look
I also encountered this bug on Eclipse Mars release build without any additional plug-in and with default formatter profile. Try formatting the following broken code by pressing Ctrl+Shift+F to get the exception: package p2; import p1.*; public class B extends A protected int f = 11; public long test B.this.f }
At least in my setup the culprit was lombok [1]. Using the latest version 1.16.4 with Mars solved the problem of strange IndexOutOfBoundsExceptions in several places. [1] https://projectlombok.org/downloads/lombok.jar
I am using Lombok 1.16.4, too. But the error also occurs in code not using any Lombok.
I had the same problem and uninstalling lombok 1.16.4 (the version which claims support for Mars release) fixed it.
Here's the corresponding ticket in the Lombok bug tracker: https://github.com/rzwitserloot/lombok/issues/872
(In reply to Oliver Gierke from comment #13) > I am using Lombok 1.16.4, too. But the error also occurs in code not using > any Lombok. I'm pretty sure that just having Lombok installed suffices to generate this bug, since Lombok patches JDT, so once it is installed, you're not running the original JDT. Can you please confirm whether the bug can be reproduced in an Eclipse installation *without* lombok? TIA.
(In reply to Stephan Herrmann from comment #16) > Can you please confirm whether the bug can be reproduced > in an Eclipse installation *without* lombok? TIA. See comment 11. I get a similar stacktrace with no additional plug-in installed on Eclipse.
(In reply to Noopur Gupta from comment #17) > (In reply to Stephan Herrmann from comment #16) > > Can you please confirm whether the bug can be reproduced > > in an Eclipse installation *without* lombok? TIA. > > See comment 11. I get a similar stacktrace with no additional plug-in > installed on Eclipse. Sorry, I missed that comment. Yes, with that example the bug can be reproduced still in HEAD. We are looking for the opening '{' of the type declaration B, but don't find it and here's the overrun (in findIndex): while (tokenType >= 0 && get(index).tokenType != tokenType) { index += forward ? 1 : -1; } @Mateusz? :)
(In reply to Stephan Herrmann from comment #18) > We are looking for the opening '{' of the type declaration B, but don't find > it and here's the overrun (in findIndex): Tough one. The formatter would not try to do it if the ast parser marked the TypeDeclaration as MALFORMED. That would make sense, wouldn't it? Can we change it this way?
Lombok 1.16.6 was just released and installing it solves the auto-completion issues. https://github.com/rzwitserloot/lombok/issues/872#issuecomment-132505315
(In reply to Mateusz Matela from comment #19) > (In reply to Stephan Herrmann from comment #18) > > We are looking for the opening '{' of the type declaration B, but don't find > > it and here's the overrun (in findIndex): > > Tough one. > The formatter would not try to do it if the ast parser marked the > TypeDeclaration as MALFORMED. That would make sense, wouldn't it? > Can we change it this way? Is there no MALFORMED, or just on too narrow a range?
(In reply to Stephan Herrmann from comment #21) > Is there no MALFORMED, or just on too narrow a range? MALFORMED is only set on the "test" field, because of the missing semicolon. But the whole type declaration should be marked too, because of the missing opening brace.
This is the log error-messages generated when I select "Source -> Generate Getters and Setters..." on a simple Java class-file attribute: !SESSION 2015-09-03 11:51:32.457 ----------------------------------------------- eclipse.buildId=4.5.0.I20150603-2000 java.version=1.8.0_45 java.vendor=Oracle Corporation BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_GB Framework arguments: -product org.eclipse.epp.package.reporting.product Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.reporting.product !ENTRY org.eclipse.jdt.ui 4 10001 2015-09-03 12:02:59.537 !MESSAGE Internal Error !STACK 0 java.lang.reflect.InvocationTargetException at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:476) at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:371) at org.eclipse.ui.internal.WorkbenchWindow$14.run(WorkbenchWindow.java:2156) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70) at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2152) at org.eclipse.ui.internal.progress.ProgressManager$RunnableWithStatus.run(ProgressManager.java:1394) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70) at org.eclipse.ui.internal.progress.ProgressManager$5.run(ProgressManager.java:1228) at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:186) at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:145) at org.eclipse.swt.widgets.Display.syncExec(Display.java:4761) at org.eclipse.ui.internal.progress.ProgressManager.runInUI(ProgressManager.java:1225) at org.eclipse.jdt.ui.actions.AddGetterSetterAction.run(AddGetterSetterAction.java:618) at org.eclipse.jdt.ui.actions.AddGetterSetterAction.generate(AddGetterSetterAction.java:549) at org.eclipse.jdt.ui.actions.AddGetterSetterAction.run(AddGetterSetterAction.java:340) at org.eclipse.jdt.ui.actions.AddGetterSetterAction.run(AddGetterSetterAction.java:584) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:279) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:251) at org.eclipse.jface.action.Action.runWithEvent(Action.java:473) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:595) at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:511) at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:420) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018) at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608) at org.eclipse.equinox.launcher.Main.run(Main.java:1515) at org.eclipse.equinox.launcher.Main.main(Main.java:1488) Caused by: java.lang.NullPointerException at org.eclipse.jdt.internal.formatter.TextEditsBuilder.bufferWhitespaceBefore(TextEditsBuilder.java:156) at org.eclipse.jdt.internal.formatter.TextEditsBuilder.token(TextEditsBuilder.java:119) at org.eclipse.jdt.internal.formatter.TokenTraverser.traverse(TokenTraverser.java:103) at org.eclipse.jdt.internal.formatter.TokenManager.traverse(TokenManager.java:378) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:161) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:139) at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.format2(CodeFormatterUtil.java:227) at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.format2(CodeFormatterUtil.java:254) at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.format(CodeFormatterUtil.java:182) at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.format(CodeFormatterUtil.java:158) at org.eclipse.jdt.internal.corext.codemanipulation.AddGetterSetterOperation.addNewAccessor(AddGetterSetterOperation.java:154) at org.eclipse.jdt.internal.corext.codemanipulation.AddGetterSetterOperation.generateGetterMethod(AddGetterSetterOperation.java:181) at org.eclipse.jdt.internal.corext.codemanipulation.AddGetterSetterOperation.run(AddGetterSetterOperation.java:324) at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39) at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:729) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2241) at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5409) at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:106) at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:463) ... 48 more Root exception: java.lang.NullPointerException at org.eclipse.jdt.internal.formatter.TextEditsBuilder.bufferWhitespaceBefore(TextEditsBuilder.java:156) at org.eclipse.jdt.internal.formatter.TextEditsBuilder.token(TextEditsBuilder.java:119) at org.eclipse.jdt.internal.formatter.TokenTraverser.traverse(TokenTraverser.java:103) at org.eclipse.jdt.internal.formatter.TokenManager.traverse(TokenManager.java:378) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:161) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:139) at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.format2(CodeFormatterUtil.java:227) at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.format2(CodeFormatterUtil.java:254) at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.format(CodeFormatterUtil.java:182) at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.format(CodeFormatterUtil.java:158) at org.eclipse.jdt.internal.corext.codemanipulation.AddGetterSetterOperation.addNewAccessor(AddGetterSetterOperation.java:154) at org.eclipse.jdt.internal.corext.codemanipulation.AddGetterSetterOperation.generateGetterMethod(AddGetterSetterOperation.java:181) at org.eclipse.jdt.internal.corext.codemanipulation.AddGetterSetterOperation.run(AddGetterSetterOperation.java:324) at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39) at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:729) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2241) at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5409) at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:106) at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:463) at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:371) at org.eclipse.ui.internal.WorkbenchWindow$14.run(WorkbenchWindow.java:2156) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70) at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2152) at org.eclipse.ui.internal.progress.ProgressManager$RunnableWithStatus.run(ProgressManager.java:1394) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70) at org.eclipse.ui.internal.progress.ProgressManager$5.run(ProgressManager.java:1228) at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:186) at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:145) at org.eclipse.swt.widgets.Display.syncExec(Display.java:4761) at org.eclipse.ui.internal.progress.ProgressManager.runInUI(ProgressManager.java:1225) at org.eclipse.jdt.ui.actions.AddGetterSetterAction.run(AddGetterSetterAction.java:618) at org.eclipse.jdt.ui.actions.AddGetterSetterAction.generate(AddGetterSetterAction.java:549) at org.eclipse.jdt.ui.actions.AddGetterSetterAction.run(AddGetterSetterAction.java:340) at org.eclipse.jdt.ui.actions.AddGetterSetterAction.run(AddGetterSetterAction.java:584) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:279) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:251) at org.eclipse.jface.action.Action.runWithEvent(Action.java:473) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:595) at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:511) at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:420) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018) at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608) at org.eclipse.equinox.launcher.Main.run(Main.java:1515) at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
(In reply to Harry Mantheakis from comment #23) > This is the log error-messages generated when I select "Source -> Generate > Getters and Setters..." on a simple Java class-file attribute: > Thank you Harry for the report, I can reproduce it (actually, not by generating getters and setters, just using a formatter profile with "Indent empty lines" and some blank lines before package declaration). But what made you attach it to this bug? It's an entirely separate problem.
Hi Mateusz I thought this bug related to the fact that Eclipse is not able to generate Java getter and setter methods (as it should). At least this is the bug I ended up being referred to when I was searching for bug-reports relating to that issue. If there is another bug-report that is more relevant, I apologise - and please advise me. Kind regards, Harry
(In reply to Harry Mantheakis from comment #25) > If there is another bug-report that is more relevant, I apologise - and > please advise me. No problem, I submitted a new bug 477005 for this. Some workaround for you would probably be to set the number of blank lines to at most 1 - I'm not sure where though - either before method declarations of before first declaration. Or, turn off "indent empty lines". You can go back to your settings and reformat everything after the code generation completes.
Thank you Mateusz - your suggestion to turn off "indent empty lines" solved the problem. For the record, running Eclipse on Windows 7, I selected to edit my Code Style formatting: Window -> Preferences -> Java -> Code Style -> Formatter I then selected to edit the current "Active Profile" in Formatter, and then under the "Indentation" tab I DISABLED (un-selected) the "Empty Lines" option. With this setting the "Source -> Generate Getters and Setters..." menu option works perfectly. Mateusz, would you like me to post my original error log in bug 477005? Thanks again!
(In reply to Mateusz Matela from comment #19) > The formatter would not try to do it if the ast parser marked the > TypeDeclaration as MALFORMED. That would make sense, wouldn't it? > Can we change it this way? Moving out of 4.6 and resetting the assignee - not my cup of tea.
(In reply to Mateusz Matela from comment #28) > (In reply to Mateusz Matela from comment #19) > > The formatter would not try to do it if the ast parser marked the > > TypeDeclaration as MALFORMED. That would make sense, wouldn't it? > > Can we change it this way? > The issue here is the parent's MALFORMED flag gets reset once the child's MALFORMED flag is set - ASTSyntaxErrorP.checkAndTagAsMalformed(). Ideally this clearing should happen only if there is no overlap - ie if the error happens above or beyond of source pos of child, then this flag should be left as it at the parent.
It's a very annoying issue. Pls consider fix it in 4.6 GA. It's very easy to reproduce this bug via below code snippet when enabling 'Save Action - format source code', import lombok.Getter; public class Model { String id; @Getter String appid; } BTW, I'm using lombok 1.16.8. java.lang.IndexOutOfBoundsException: Index: 27, Size: 27 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at org.eclipse.jdt.internal.formatter.TokenManager.get(TokenManager.java:74) at org.eclipse.jdt.internal.formatter.TokenManager.findIndex(TokenManager.java:167) at org.eclipse.jdt.internal.formatter.SpacePreparator.handleEmptyParens(SpacePreparator.java:1005) at org.eclipse.jdt.internal.formatter.SpacePreparator.visit(SpacePreparator.java:205) at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:611) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2782) at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:470) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711) at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2782) at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:212) at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2711) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.prepareSpaces(DefaultCodeFormatter.java:356) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.prepareFormattedCode(DefaultCodeFormatter.java:195) at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:157) at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.reformat(CodeFormatterUtil.java:323) at org.eclipse.jdt.internal.corext.fix.CodeFormatFix.createCleanUp_aroundBody0(CodeFormatFix.java:74) at org.eclipse.jdt.internal.corext.fix.CodeFormatFix$AjcClosure1.run(CodeFormatFix.java:1)
BTW, Eclipse is Mars.SR.2 GA. The same error always happens when using 'ctrl+shift+f' to format the entire sample code.
bulk move out of 4.8
Bulk move out of 4.10
New Gerrit change created: https://git.eclipse.org/r/139940
(In reply to Stephan Herrmann from comment #18) > We are looking for the opening '{' of the type declaration B, but don't find > it and here's the overrun (in findIndex): This can also happen while searching for a closing bracket. To reproduce try to format the following two lines of code: =============== public class BuggedFormatter { public static void main(String[] args) { =============== If formatted using keyboard shortcut the logged error is a bit different. If formatted through Save Actions an additional warning dialog is shown. (In reply to Eclipse Genie from comment #34) > New Gerrit change created: https://git.eclipse.org/r/139940 This change fixes this particular problem but there may be have not checked for more similar problems.
Sorry I forgot to run the formatter tests beforehand and while fixing the IndexOutOfBoundsException my change at the same time seem to break formatting in other cases. So the problem still exist but my change may not be the right solution.
*** Bug 552477 has been marked as a duplicate of this bug. ***
(In reply to Paul Pazderski from comment #36) I don't think it's the right approach at all. It takes care of one particular syntax error while there can potentially be countless other types. With this approach we'd need to have additional checking each time the formatter needs to do something with a token, because that token might not exist. That's infeasible. It's the compiler's job to properly mark AST nodes as invalid so that the formatter won't try to touch them. Comment 29 seems to have the right suggestion, but I'm not familiar enough with the compiler to implement it. If it's too costly to change the compiler, maybe the UI or the formatter itself can just catch these kinds of exception and either ignore or silently log them instead of showing a warning dialog. This would make it harder to detect future bugs, but I don't remember any reported exceptions in the recent years other than for code having errors - so maybe the formatter is mature enough for this approach.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.