Community
Participate
Working Groups
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)
Which build? Can you attach the CU (or a similar example) which causes the problem?
Please provide steps to reproduce and build ID.
Please reopen once info is made available.
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.
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.
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; } }
I am investigating.
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.
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.
With this patch, all JDT/Core + JDT/UI + JDT/UI refactoring tests passed.
Created attachment 11827 [details] New regression tests. Apply on HEAD Regression tests for this bug
Fixed and released in HEAD. Regression tests added.
Verified for 3.0RC2