Bug 23361 Java Model Exception when renaming a compilation unit
Build 200209031019 I have a special test case which generates a Java Model Exception, a funny thing (for me) it's I can't reproduce it two times with the same compilation unit names, even if I stop and restart Eclipse. 1. Create the two following compilation units : public class TestCompiler_1 { public static void main(String[] args) { TestCompiler_2.foo(); } } ------------ public class TestCompiler_2 { public static void foo() { System.out.println("test"); } } 2. Export TestCompiler_2 in a jar file. 3. Add the created jar file in the classpath. 4. Rename TestCompiler_2 to TestCompiler_2_src, in the "Rename compilation unit" dialog, uncheck "Update references to renamed element". The following stack trace is written in the log file : !SESSION Sep 10, 2002 09:11:55.521 --------------------------------------------- java.version=1.4.1-beta java.vendor=Sun Microsystems Inc. BootLoader constants: OS=linux, ARCH=x86, WS=gtk, NL=en_US Command-line arguments: -dev bin -data /home/lbourlie/workspaces/selfhost/ -os linux -ws gtk -arch x86 !ENTRY org.eclipse.jdt.ui 4 1 Sep 10, 2002 09:11:55.542 !MESSAGE Internal Error !STACK 1 Java Model Exception: Java Model Status [TestCompiler_2.java does not exist.] at org.eclipse.jdt.internal.core.JavaElement.newNotPresentException(JavaElement.java:500) at org.eclipse.jdt.internal.core.Openable.getUnderlyingResource(Openable.java:254) at org.eclipse.jdt.internal.core.CompilationUnit.getCorrespondingResource(CompilationUnit.java:412) at org.eclipse.jdt.ui.actions.ShowInNavigatorViewAction.getResource(ShowInNavigatorViewAction.java:175) at org.eclipse.jdt.ui.actions.ShowInNavigatorViewAction.getResource(ShowInNavigatorViewAction.java:154) at org.eclipse.jdt.ui.actions.ShowInNavigatorViewAction.selectionChanged(ShowInNavigatorViewAction.java:93) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchSelectionChanged(SelectionDispatchAction.java:181) at org.eclipse.jdt.ui.actions.SelectionDispatchAction.selectionChanged(SelectionDispatchAction.java:176) at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:147) at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:1155) at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:904) at org.eclipse.jdt.internal.ui.javaeditor.JavaOutlinePage.select(JavaOutlinePage.java:854) at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.synchronizeOutlinePageSelection(CompilationUnitEditor.java:1309) at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$3.run(CompilationUnitEditor.java:1346) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:31) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:95) at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:1356) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1226) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1256) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1239) at org.eclipse.core.internal.boot.InternalBootLoader.run(InternalBootLoader.java:775) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:432) at EclipseRuntimeLauncher.main(EclipseRuntimeLauncher.java:24) !ENTRY org.eclipse.jdt.core 4 969 Sep 10, 2002 09:11:55.555 !MESSAGE TestCompiler_2.java does not exist.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/ShowInNavigatorViewAction.java
}
	
	private IResource getResource(IJavaElement element) throws JavaModelException {
		if (element == null)
			return null;
		if (element instanceof IMember) {
			IOpenable openable= ((IMember)element).getOpenable();
			if (openable instanceof IJavaElement)
				element= (IJavaElement)openable;
			else
				element= null;
		}
		if (element instanceof ICompilationUnit) {
			ICompilationUnit unit= (ICompilationUnit)element;
			if (unit.isWorkingCopy())
				element= unit.getOriginalElement();
		}
		if (element == null)
			return null;
		IResource result= element.getCorrespondingResource();
		if (result == null)
			result= element.getUnderlyingResource();
		return result;
	}
	
	private static String getDialogTitle() {
		return ActionMessages.getString("ShowInNavigatorView.dialog.title"); 
	}	
}