Bug 38732 - organize imports does not work with assert in source code
Summary: organize imports does not work with assert in source code
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows All
: P3 normal (vote)
Target Milestone: 2.1.3   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords: usability
: 42647 45340 45529 72458 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-06-10 16:08 EDT by Peter Boheme CLA
Modified: 2004-08-23 15:58 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Boheme CLA 2003-06-10 16:08:42 EDT
 
Comment 1 Peter Boheme CLA 2003-06-10 16:23:00 EDT
public class Test{
public static void main(String[] args) {
  assert(true);
  BigDecimal f = null;
 }
}

if i have an assert in my source-code the "Organize imports" functionality does 
not work anymore. If i comment-out it does.

System:
java.runtime.version=1.4.2-beta-b19
os.name=Windows XP
Version: 2.1.0
Build id: 200303272130 and 200306051737 i tested
Comment 2 Martin Aeschlimann CLA 2003-06-11 09:44:12 EDT
Can't reproduce this.
My guess is that you set the compiler compliance settings (Preferences > Java > 
Compiler > Compliance) to 1.4 including the source compatibility to 1.4.
Note that if you have this setting, you can not use assert(true) anymore as 
assert is a keyword in 1.4 source mode.

Comment 3 Martin Aeschlimann CLA 2003-06-11 09:53:12 EDT
Seems to be a AST problem:
Set the source compliance mode to 1.4 and create an AST of the code:

java.lang.IllegalArgumentException
	at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java:1469)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1799)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1709)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:720)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations
(ASTConverter.java:243)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:182)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:80)
	at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:267)
	at 
org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.<init>
(OrganizeImportsOperation.java:458)
	at 
org.eclipse.jdt.internal.corext.codemanipulation.OrganizeImportsOperation.<init>
(OrganizeImportsOperation.java:462)
	at org.eclipse.jdt.ui.actions.OrganizeImportsAction.run
(OrganizeImportsAction.java:406)
	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:848)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2036)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1742)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1399)
	at org.eclipse.ui.internal.Workbench.run(Workbench.java:1382)
	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)
Comment 4 Olivier Thomann CLA 2003-06-11 11:00:34 EDT
What are your settings? Do you use source 1.4 or 1.3?
In 1.4, you should have a compile error. I will investigate.
Comment 5 Olivier Thomann CLA 2003-06-11 12:05:35 EDT
Fixed and released in HEAD contents.
Regression tests added.
Comment 6 Olivier Thomann CLA 2003-06-11 12:29:12 EDT
Forget about it. assert(true); is seen as a assert statement with a
parenthesized expression. So there is no compile error and I fixed it.
Comment 7 David Audel CLA 2003-07-16 05:46:45 EDT
Verified.
Comment 8 Olivier Thomann CLA 2003-09-08 10:11:54 EDT
*** Bug 42647 has been marked as a duplicate of this bug. ***
Comment 9 Olivier Thomann CLA 2003-09-08 10:12:07 EDT
I have the fix ready to be backported to 2.1. maintenance stream.
Comment 10 Martin Aeschlimann CLA 2003-10-23 14:08:42 EDT
*** Bug 45340 has been marked as a duplicate of this bug. ***
Comment 11 Olivier Thomann CLA 2003-10-26 15:50:01 EST
*** Bug 45529 has been marked as a duplicate of this bug. ***
Comment 12 Olivier Thomann CLA 2003-12-04 11:43:17 EST
Backported to 2.1.3.
Comment 13 Frederic Fusier CLA 2004-03-01 10:28:57 EST
Verified for 2.1.3 with build I200402251535.
Comment 14 Frederic Fusier CLA 2004-03-01 12:09:56 EST
Build was M200402251535 and not I200402251535....
Comment 15 Olivier Thomann CLA 2004-08-23 15:58:48 EDT
*** Bug 72458 has been marked as a duplicate of this bug. ***