Bug 68829

Summary: refactory doesn't work properly when "assert" is used in java code
Product: [Eclipse Project] JDT Reporter: worookie <worookie>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: critical    
Priority: P3    
Version: 3.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description worookie CLA 2004-06-28 19:10:46 EDT
enviroment: Sun jdk1.4.2_04 on Windows 2000 Server

For eclipse v3.0:
When an "assert" statement is used in a java code, and the JDK compliance is set
to 1.4 (in order to enable the "assert" feature), the refactory function is not
available. Please see the screenshot at:
http://www.javaworld.com.tw/jute/upload/2004/06/29/65845852.gif

For eclipse v2.1.3:
When an "assert" statement is used in a java code, and the JDK compliance is set
to 1.4 (in order to enable the "assert" feature), the refactory function doesn't
work. Please see picture:
http://www.javaworld.com.tw/jute/upload/2004/06/24/97320716.gif
There is no response after clicking on "Rename..." in the picture.
Comment 1 Dirk Baeumer CLA 2004-06-29 12:55:15 EDT
Only setting the Compliance Level to 1.4 is enough. To get assert support you 
have to set the source and class file compatibility to 1.4 as well 
(uncheck "Use defautl compliance level).

I tested it with 

public class A {
	
	public static void main(String[] args) {
		assert (true) : "Testing";
	}
	
	public void foo() {
		assert (true) : "Testing";
	}
}

and it works. But please note that you can't rename main method.
Comment 2 worookie CLA 2004-06-29 14:18:34 EDT
There must be some different settings between yours and my environment.
I did the same configurations (for both v.2.1.3 and v.3.0) as you did:
Set the Compliance Level to 1.4 and set the source and class file compatibility
to 1.4 as well (uncheck "Use defautl compliance level).
But I still have the problem with refactoring.
Please let me know if you need any further info from my side in order to assist
you to reproduce this bug. Thanks.

By the way, of course we can rename the "main" method. If you cannot rename it
with your eclipse, then it is probably a bug.
Comment 3 worookie CLA 2004-06-29 14:27:15 EDT
Here shows the error messages in the .log file (of eclipse v. 3.0) when trying
to use the refactoring feature (via right-clicking through the method name).

==================================================================

!ENTRY org.eclipse.ui 4 0 &#20845;&#26376; 29, 2004 11:19:04.323
!MESSAGE java.lang.IllegalArgumentException
!STACK 0
java.lang.IllegalArgumentException
	at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java:2587)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1894)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1810)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:770)
	at
org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:336)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:274)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:152)
	at org.eclipse.jdt.core.dom.ASTParser.convert(ASTParser.java:711)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:681)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:574)
	at
org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.createAST(ASTProvider.java:439)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.getAST(ASTProvider.java:391)
	at
org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection.resolvePartialAstAtOffset(JavaTextSelection.java:94)
	at
org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection.resolveSelectedNodes(JavaTextSelection.java:103)
	at
org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection.resolveInMethodBody(JavaTextSelection.java:125)
	at
org.eclipse.jdt.ui.actions.ExtractMethodAction.canEnable(ExtractMethodAction.java:84)
	at
org.eclipse.jdt.ui.actions.ExtractMethodAction.selectionChanged(ExtractMethodAction.java:80)
	at
org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged(SelectionDispatchAction.java:202)
	at
org.eclipse.jdt.ui.actions.SelectionDispatchAction.update(SelectionDispatchAction.java:114)
	at
org.eclipse.jdt.ui.actions.RefactorActionGroup.refactorMenuShown(RefactorActionGroup.java:512)
	at
org.eclipse.jdt.ui.actions.RefactorActionGroup.access$1(RefactorActionGroup.java:497)
	at
org.eclipse.jdt.ui.actions.RefactorActionGroup$1.menuAboutToShow(RefactorActionGroup.java:451)
	at org.eclipse.jface.action.MenuManager.fireAboutToShow(MenuManager.java:286)
	at org.eclipse.jface.action.MenuManager.handleAboutToShow(MenuManager.java:370)
	at org.eclipse.jface.action.MenuManager.access$0(MenuManager.java:367)
	at org.eclipse.jface.action.MenuManager$2.menuShown(MenuManager.java:383)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:116)
	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.Widget.sendEvent(Widget.java:820)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:801)
	at org.eclipse.swt.widgets.Control.WM_INITMENUPOPUP(Control.java:3320)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:2993)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1391)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:3338)
	at org.eclipse.swt.internal.win32.OS.TrackPopupMenu(Native Method)
	at org.eclipse.swt.widgets.Menu._setVisible(Menu.java:222)
	at org.eclipse.swt.widgets.Display.runPopups(Display.java:2798)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2425)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1377)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1348)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:254)
	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:335)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129)
	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.core.launcher.Main.basicRun(Main.java:183)
	at org.eclipse.core.launcher.Main.run(Main.java:644)
	at org.eclipse.core.launcher.Main.main(Main.java:628)
Comment 4 worookie CLA 2004-06-29 14:32:57 EDT
Regarding renaming the "main" method. We can do it in v. 2.1.3 but cannot do it
in v. 3.0.
Comment 5 Dirk Baeumer CLA 2004-06-30 05:12:12 EDT
This is a dup of 68823. The problem is that the AST creation fails, hence no 
refactoring is available.

Please provide steps to reproduce the problem (best would be source code 
showing the problem).
Comment 6 Dirk Baeumer CLA 2004-07-01 05:07:27 EDT

*** This bug has been marked as a duplicate of 68823 ***