Community
Participate
Working Groups
Organize import fails without any error if code contains Java 1.4 assert(). It works if all assert() are commented out.
Works for me. Do you have a small code snippet so I can reproduce this? Please also specify what you have set in Preference > Java > Compiler > Compliance: JDK compliance. I suspect you have source compatibility to 1.4.
The following code will cause problem. If you comment out the assert() line, 'Organize Imports' will work fine. I just reinstalled the latest release version of Eclipse. The only change in option is compliance 1.4. ---BEGIN CODE--- import java.util.Vector; public class TestImport { public static void main(String[] astrArgs) { assert(astrArgs.length > 0); Vector vObjs = new Vector(); ArrayList alstNames = new ArrayList(); } } ---END CODE---
Seems to be fixed in 3.0. Can you look if there is something in the '.log' file? (.metadata/.log) There's a known bug with the settings in 2.1.1: 1.4 compatibility should be: .classfiles 1.2 sourcefiles: 1.3 assert: warning (so our compiler is compaitible with javac's 14. mode) Try this and see if it works. Thanks!
Using the following settings as suggested fix the organize imports problem. 1.4 compatibility should be: .classfiles 1.2 sourcefiles: 1.3 assert: warning If only 1.4 compatibility is selected without the above changes, an exception is recorded in .log file. !SESSION Oct 23, 2003 10:33:20.03 --------------------------------------------- - java.version=1.4.1_01 java.vendor=Sun Microsystems Inc. BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US Command-line arguments: -os win32 -ws win32 -arch x86 -install file:C:/eclipse/ !ENTRY org.eclipse.ui 4 4 Oct 23, 2003 10:33:20.03 !MESSAGE Unhandled exception caught in event loop. !ENTRY org.eclipse.ui 4 0 Oct 23, 2003 10:33:20.13 !MESSAGE java.lang.IllegalArgumentException !STACK 0 java.lang.IllegalArgumentException at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java:1469) at org.eclipse.jdt.core.dom.ASTConverter.convert (ASTConverter.java:1801) at org.eclipse.jdt.core.dom.ASTConverter.convert (ASTConverter.java:1708) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:719) at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations (ASTConverter.java:242) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:181) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:79) at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:265) at org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.findT ypeReferences(OrganizeImportsOperation.java:523) at org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.run (OrganizeImportsOperation.java:471) at org.eclipse.jdt.internal.core.BatchOperation.executeOperation (BatchOperation.java:34) at org.eclipse.jdt.internal.core.JavaModelOperation.execute (JavaModelOperation.java:365) at org.eclipse.jdt.internal.core.JavaModelOperation.run (JavaModelOperation.java:684) at org.eclipse.core.internal.resources.Workspace.run (Workspace.java:1595) at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:2711) at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run (WorkbenchRunnableAdapter.java:42) at org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext$BusyRunnable.inte rnalRun(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.jdt.ui.actions.OrganizeImportsAction.run (OrganizeImportsAction.java:402) at org.eclipse.jdt.ui.actions.OrganizeImportsAction.run (OrganizeImportsAction.java:248) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun (SelectionDispatchAction.java:193) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run (SelectionDispatchAction.java:169) at org.eclipse.jface.action.Action.runWithEvent(Action.java:842) at org.eclipse.ui.internal.WWinKeyBindingService.pressed (WWinKeyBindingService.java:214) at org.eclipse.ui.internal.WWinKeyBindingService$5.widgetSelected (WWinKeyBindingService.java:332) at org.eclipse.ui.internal.AcceleratorMenu$2.handleEvent (AcceleratorMenu.java:68) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:81) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:840) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1838) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1545) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1402) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1385) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:858) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461) 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:291) at org.eclipse.core.launcher.Main.run(Main.java:747) at org.eclipse.core.launcher.Main.main(Main.java:583)
Thanks for the information! *** This bug has been marked as a duplicate of 38732 ***
Remove the parenthesis around your expression in the asser statement. This will fix it. The fix is only in the 3.0 stream.