Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 319006 - [Refactoring] BadLocationException on Rename Enum with additional constructor
Summary: [Refactoring] BadLocationException on Rename Enum with additional constructor
Status: RESOLVED NOT_ECLIPSE
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Markus Keller CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-06 09:06 EDT by leskien CLA
Modified: 2010-07-30 04:30 EDT (History)
1 user (show)

See Also:


Attachments
java class for refactoring (485 bytes, application/octet-stream)
2010-07-29 08:57 EDT, leskien CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description leskien CLA 2010-07-06 09:06:03 EDT
Build Identifier: I20100608-0911

Code:
  public enum MyNames {

    Name1(30000L, 230000L),//
      Name2(30000L, 180000L);

    protected Long value1;
    protected Long value2;

    private MyNames(Long val1, Long val2) {
      this.value1 = val1;
      this.value2 = val2;
    }

    public Long getValue1() {
      return value1;
    }

    public Long getValue2() {
      return value2;
    }
  }

causes the refactoring to fail with a BadLocationException:

!ENTRY org.eclipse.jdt.ui 4 10001 2010-07-06 15:03:47.132
!MESSAGE Internal Error
!STACK 0
org.eclipse.jface.text.BadLocationException: First position: 'MyNames' at 274, this position: 'MyNames(Long val1, Long val2)' at 412
	at org.eclipse.jface.text.link.LinkedPositionGroup.enforceEqualContent(LinkedPositionGroup.java:132)
	at org.eclipse.jface.text.link.LinkedPositionGroup.addPosition(LinkedPositionGroup.java:113)
	at org.eclipse.jdt.internal.ui.refactoring.reorg.RenameLinkedMode.start(RenameLinkedMode.java:253)
	at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.run(RenameJavaElementAction.java:201)
	at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.doRun(RenameJavaElementAction.java:148)
	at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.run(RenameJavaElementAction.java:129)
	at org.eclipse.jdt.ui.actions.RenameAction.run(RenameAction.java:115)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:278)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:250)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
	at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:185)
	at org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:109)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:468)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:786)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:885)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:567)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:508)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:123)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1253)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
	at org.eclipse.swt.widgets.Control.traverse(Control.java:3693)
	at org.eclipse.swt.widgets.Control.translateMnemonic(Control.java:3537)
	at org.eclipse.swt.widgets.Composite.translateMnemonic(Composite.java:1190)
	at org.eclipse.swt.widgets.Control.translateMnemonic(Control.java:3555)
	at org.eclipse.swt.widgets.Display.translateMnemonic(Display.java:4673)
	at org.eclipse.swt.widgets.Display.filterMessage(Display.java:1267)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3653)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	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.equinox.launcher.Main.invokeFramework(Main.java:619)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1407)

Reproducible: Always

Steps to Reproduce:
1. Create the enum as class MyNames listed above
2. Choose "Refactor" | "Rename"
3. Obtain the stacktrace from .log
Comment 1 Prakash Rangaraj CLA 2010-07-29 03:03:16 EDT
Moving to JDT UI
Comment 2 Dani Megert CLA 2010-07-29 03:37:19 EDT
Are you sure you used I20100608-0911? We fixed a bug in 3.6 and I cannot reproduce with your example.

Markus, please give a try as well.
Comment 3 leskien CLA 2010-07-29 04:31:01 EDT
Yes, I just in that moment reproduced it again with the build id as copied out from the "About" dialog.
Comment 4 Markus Keller CLA 2010-07-29 08:31:51 EDT
I also can't reproduce this. Could you please:

- attach the complete file (the positions in the stack trace don't match the given snippet, and other code in the file is probably the reason for the wrong offsets)

- tell exactly where the caret is (or what text range is selected) when you start the refactoring

- tell how exactly you start the refactoring (I can't reproduce even the bottom of your stacktrace -- I would expect a MenuItem or a StyledText in there)
Comment 5 leskien CLA 2010-07-29 08:57:56 EDT
Created attachment 175491 [details]
java class for refactoring
Comment 6 leskien CLA 2010-07-29 08:59:35 EDT
again the stack trace:
!ENTRY org.eclipse.jdt.ui 4 10001 2010-07-29 14:56:27.980
!MESSAGE Internal Error
!STACK 0
org.eclipse.jface.text.BadLocationException: First position: 'MyNames' at 144, this position: 'MyNames(Long val1, Long val2)' at 282
	at org.eclipse.jface.text.link.LinkedPositionGroup.enforceEqualContent(LinkedPositionGroup.java:132)
	at org.eclipse.jface.text.link.LinkedPositionGroup.addPosition(LinkedPositionGroup.java:113)
	at org.eclipse.jdt.internal.ui.refactoring.reorg.RenameLinkedMode.start(RenameLinkedMode.java:253)
	at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.run(RenameJavaElementAction.java:201)
	at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.doRun(RenameJavaElementAction.java:148)
	at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.run(RenameJavaElementAction.java:129)
	at org.eclipse.jdt.ui.actions.RenameAction.run(RenameAction.java:115)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:278)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:250)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
	at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
	at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	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:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
Comment 7 leskien CLA 2010-07-29 09:01:03 EDT
I created a new project, added as only class the attached. Then I marked the class name (MyNames), used the mouse with right-click and chose Refactore - Rename.
Comment 8 Markus Keller CLA 2010-07-29 09:46:45 EDT
I still couldn't reproduce with the given steps in an unshared new Java project.

Do you use a team provider (CVS, SVN, Git, ...)? If something modifies the file (e.g. updates the "@version $Revision: $, $Date: $, $Author: $" in the Javadoc) before the refactoring starts, then that would explain the wrong offsets.
Comment 9 leskien CLA 2010-07-30 00:11:16 EDT
yes, we're using CVS with our sources
Comment 10 leskien CLA 2010-07-30 00:17:10 EDT
For testing purpose i created a new workspace again, created a new java project again, made sure the project is not shared, and added the class. The refactoring still fails (but different offset values):

!ENTRY org.eclipse.jdt.ui 4 10001 2010-07-30 06:13:28.561
!MESSAGE Internal Error
!STACK 0
org.eclipse.jface.text.BadLocationException: First position: 'MyNames' at 14, this position: 'MyNames(Long val1, Long val2)' at 161
	at org.eclipse.jface.text.link.LinkedPositionGroup.enforceEqualContent(LinkedPositionGroup.java:132)
	at org.eclipse.jface.text.link.LinkedPositionGroup.addPosition(LinkedPositionGroup.java:113)
	at org.eclipse.jdt.internal.ui.refactoring.reorg.RenameLinkedMode.start(RenameLinkedMode.java:253)
	at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.run(RenameJavaElementAction.java:201)
	at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.doRun(RenameJavaElementAction.java:148)
	at org.eclipse.jdt.internal.ui.refactoring.actions.RenameJavaElementAction.run(RenameJavaElementAction.java:129)
	at org.eclipse.jdt.ui.actions.RenameAction.run(RenameAction.java:115)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:278)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:250)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
	at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
	at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	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:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
Comment 11 leskien CLA 2010-07-30 00:18:01 EDT
Possibly anything to do with plugins ... ?
Comment 12 leskien CLA 2010-07-30 00:36:11 EDT
within a new installation without any plugins it works. I'll go ahead and add more and more plugins to see which one will let it fail.
Comment 13 leskien CLA 2010-07-30 02:41:05 EDT
systematic check with the plugins found:

Groovy Plugin creates the problem (http://dist.springsource.org/release/GRECLIPSE/e3.6/).
Comment 14 Dani Megert CLA 2010-07-30 03:49:53 EDT
>Groovy Plugin creates the problem
Please file the bug there.
Comment 15 leskien CLA 2010-07-30 04:29:57 EDT
Posted issue at http://jira.codehaus.org/browse/GRECLIPSE-807
Comment 16 leskien CLA 2010-07-30 04:30:08 EDT
thx for your help