Bug 66216 - Sort Members is broken.
Summary: Sort Members is broken.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.0 RC2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-08 16:08 EDT by Brian Howard CLA
Modified: 2004-06-11 07:32 EDT (History)
2 users (show)

See Also:


Attachments
Apply on HEAD (2.17 KB, patch)
2004-06-09 14:18 EDT, Olivier Thomann CLA
no flags Details | Diff
New regression tests. Apply on HEAD (6.48 KB, patch)
2004-06-09 15:31 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Howard CLA 2004-06-08 16:08:43 EDT
Selecting Source->Sort Members results in the following exception: 

java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at java.lang.StringBuffer.append(StringBuffer.java:499)
	at
org.eclipse.jdt.internal.core.SortElementBuilder$SortMultipleFieldDeclaration.generateSource(SortElementBuilder.java:603)
	at
org.eclipse.jdt.internal.core.SortElementBuilder$SortType.generateSource(SortElementBuilder.java:801)
	at
org.eclipse.jdt.internal.core.SortElementBuilder$SortAbstractMethodDeclaration.generateSource(SortElementBuilder.java:207)
	at
org.eclipse.jdt.internal.core.SortElementBuilder$SortType.generateSource(SortElementBuilder.java:801)
	at
org.eclipse.jdt.internal.core.SortElementBuilder$SortCompilationUnit.generateSource(SortElementBuilder.java:896)
	at
org.eclipse.jdt.internal.core.SortElementBuilder.getSource(SortElementBuilder.java:948)
	at
org.eclipse.jdt.internal.core.SortElementsOperation.processElement(SortElementsOperation.java:117)
	at
org.eclipse.jdt.internal.core.SortElementsOperation.executeOperation(SortElementsOperation.java:74)
	at
org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:700)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1673)
	at
org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:744)
	at
org.eclipse.jdt.core.util.CompilationUnitSorter.sort(CompilationUnitSorter.java:174)
	at
org.eclipse.jdt.internal.corext.codemanipulation.SortMembersOperation.run(SortMembersOperation.java:248)
	at
org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:34)
	at
org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:700)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1673)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:3246)
	at
org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:65)
	at
org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext$BusyRunnable.internalRun(BusyIndicatorRunnableContext.java:113)
	at
org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext$BusyRunnable.run(BusyIndicatorRunnableContext.java:80)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
	at
org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext.run(BusyIndicatorRunnableContext.java:126)
	at org.eclipse.ui.internal.progress.ProgressManager$5.run(ProgressManager.java:980)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
	at
org.eclipse.ui.internal.progress.ProgressManager.runInUI(ProgressManager.java:976)
	at org.eclipse.jdt.ui.actions.SortMembersAction.run(SortMembersAction.java:205)
	at org.eclipse.jdt.ui.actions.SortMembersAction.run(SortMembersAction.java:138)
	at
org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:212)
	at
org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:188)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:881)
	at
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:915)
	at
org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:866)
	at
org.eclipse.jface.action.ActionContributionItem$7.handleEvent(ActionContributionItem.java:785)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2716)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2382)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1363)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1334)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:253)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:141)
	at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:96)
	at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:334)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:128)
	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:185)
	at org.eclipse.core.launcher.Main.run(Main.java:638)
	at org.eclipse.core.launcher.Main.main(Main.java:622)
Comment 1 Dani Megert CLA 2004-06-09 04:25:33 EDT
Which build?
Can you attach the CU (or a similar example) which causes the problem?
Comment 2 Philipe Mulet CLA 2004-06-09 04:36:19 EDT
Please provide steps to reproduce and build ID.
Comment 3 Philipe Mulet CLA 2004-06-09 04:36:43 EDT
Please reopen once info is made available.
Comment 4 Brian Howard CLA 2004-06-09 10:17:57 EDT
Here is the build info:

eclipse.buildId=I200405290105
java.version=1.4.2_02
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US

This happens with some classes altough I'm not sure what the correlation is. I
have verified this on two seperate machines with two seperate class files. I
just tested a third and it appeared to work without a problem. To reproduce it
all I have to do is attempt to run the Sort Members tool, the dialog box appears
warning me about losing break points, etc and then nothing appears to happen. It
is deterministic in that running the particular class always produces this error. 

Unfortunately I can't send the class due to employer restrictions, so I tried to
strip the class down to empty methods so that I could send it as an attachment,
but there were no errors running the stripped down class. The class contains
methods (private, public, protected, and some static), attributes, constructors,
an inner class, and a static initializer. 

I will do some further testing to see if I can find what is specific to the
class that would cause the error.
Comment 5 Olivier Thomann CLA 2004-06-09 10:37:38 EDT
Could you please extract all the code relative the multiple field declarations?
The problem occurs in a multiple field declaration.
Something like this:
int i, j, k;

Thanks.
Comment 6 Brian Howard CLA 2004-06-09 11:21:25 EDT
Thanks to Olivier's post I have created a small class that breaks everytime. It
appears to break when an inner class or an anonymous class inside of a method
uses multiple field declarations. 

However I have discovered something else that appears to break it. If you
comment out the multiple field declartions in class E and the anonymous class
then it still breaks until you comment out class D. Just having an inner class
within the method which is below an anonymous class causes the sort to break also.

public class SortMembersBreakTest {
   
   public void c() {
      
   }
   
   public void b() {
      
   }
   
   public void a() {
      class E {
         // this is the line that breaks the Sort Members.
         // comment this fix the problem.
         int x, y;
      }
      
      
      new Object() {
         // it breaks in an anonymous class also.
         // comment this fix the problem.
         int x, y;
      }; 
      
      
      class D {
         // this appears to break also.
      }
   } 
   
   private class F {
      // but this works fine
      int x, y;
   }
}
Comment 7 Olivier Thomann CLA 2004-06-09 11:25:33 EDT
I am investigating.
Comment 8 Olivier Thomann CLA 2004-06-09 12:55:59 EDT
Reproduced. The problem comes from a wrong fieldEndPosition for the field
declaration located inside a local class inside a method.
I need to assess the risk of a fix for this issue.
Comment 9 Olivier Thomann CLA 2004-06-09 14:18:21 EDT
Created attachment 11816 [details]
Apply on HEAD

This patch fixes the fieldEndPosition for field declaration inside a class
located inside a method declaration. Doing this, no other changes is required.
The Sort member operation is working as is.
Comment 10 Olivier Thomann CLA 2004-06-09 15:29:16 EDT
With this patch, all JDT/Core + JDT/UI + JDT/UI refactoring tests passed.
Comment 11 Olivier Thomann CLA 2004-06-09 15:31:45 EDT
Created attachment 11827 [details]
New regression tests. Apply on HEAD

Regression tests for this bug
Comment 12 Olivier Thomann CLA 2004-06-10 10:04:29 EDT
Fixed and released in HEAD.
Regression tests added.
Comment 13 David Audel CLA 2004-06-11 07:32:39 EDT
Verified for 3.0RC2