Bug 99600 - [search] Java model exception on "Move to new file" on inner type with inner type
Summary: [search] Java model exception on "Move to new file" on inner type with inner ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 RC3   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-13 06:21 EDT by David Saff CLA
Modified: 2005-06-16 13:32 EDT (History)
3 users (show)

See Also:


Attachments
Patch to fix this issue (2.14 KB, patch)
2005-06-14 12:55 EDT, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Saff CLA 2005-06-13 06:21:58 EDT
In RC2.

Given code:

import java.util.EnumMap;

public class Exposer {
	public enum Category {
		GROCERIES, MORTGAGE
	}

	public class Account {
		class CategorySpending extends EnumMap<Category, Integer> {
			private static final long serialVersionUID = 1L;

			private CategorySpending() {
				super(Category.class);
			}

			int spendingIn(Category category) {
				if (!containsKey(category))
					return 0;
				return get(category);
			}
		}

		private final CategorySpending _spent = new CategorySpending();

		public void spend(Category category, int amount) {
			_spent.put(category,
					_spent.spendingIn(category) + amount);
		}
	}
}

Trying to invoke "Move member type to new file" on Account results in the error
trace below.  A very similar error occurs if you try to move instance method
spend to class CategorySpending:

Java Model Exception: Java Model Status [spendingIn(Exposer.Category)
{key=Lnet/saff/Exposer$Account$CategorySpending;.spendingIn(Lnet/saff/Exposer$Category;)I}
[in CategorySpending [in Account [in Exposer [in [Working copy] Exposer.java [in
net.saff [in <project root> [in dupfinder]]]]]]] does not exist]
	at
org.eclipse.jdt.internal.core.JavaElement.newNotPresentException(JavaElement.java:468)
	at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:499)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:232)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:218)
	at org.eclipse.jdt.internal.core.Member.getFlags(Member.java:147)
	at
org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.adjustOutgoingVisibility(MemberVisibilityAdjustor.java:671)
	at
org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.adjustOutgoingVisibility(MemberVisibilityAdjustor.java:690)
	at
org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.adjustOutgoingVisibility(MemberVisibilityAdjustor.java:722)
	at
org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.adjustVisibility(MemberVisibilityAdjustor.java:763)
	at
org.eclipse.jdt.internal.corext.refactoring.structure.MoveInnerToTopRefactoring.createChangeManager(MoveInnerToTopRefactoring.java:815)
	at
org.eclipse.jdt.internal.corext.refactoring.structure.MoveInnerToTopRefactoring.checkFinalConditions(MoveInnerToTopRefactoring.java:742)
	at
org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:84)
	at
org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:114)
	at
org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:189)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1719)
	at
org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:86)
	at
org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113)
Comment 1 Dirk Baeumer CLA 2005-06-13 18:56:58 EDT
Tobias, can you please investigate.
Comment 2 Tobias Widmer CLA 2005-06-14 10:39:37 EDT
The member visibility adjustor calls IMember#getFlags on the 
ResolvedSourceMethod for spendingIn, which has been obtained from the search 
engine. The toString() output looks like this:

spendingIn(Exposer.Category) (not open) 
{key=LSub~Exposer$Account$CategorySpending;.spendingIn(LExposer$Category;)I} 
[in CategorySpending [in Account [in Exposer [in [Working copy] Sub.java [in 
<default> [in <project root> [in Test]]]]]]]

Moving to JDT Core for comments
Comment 3 Frederic Fusier CLA 2005-06-14 12:55:22 EDT
Created attachment 23071 [details]
Patch to fix this issue
Comment 4 Frederic Fusier CLA 2005-06-14 12:56:12 EDT
philippe, may be a candidate for RC3?
Comment 5 Philipe Mulet CLA 2005-06-14 15:43:09 EDT
+1 for RC3

Dirk - pls cast your vote.
Comment 6 Dirk Baeumer CLA 2005-06-14 16:43:38 EDT
+1 for RC3.
Comment 7 Frederic Fusier CLA 2005-06-15 02:32:09 EDT
Fixed and released in HEAD.

A smaller test case is:
public class Test {
	public class C1 {}
	public class C2 {
		class C3 {
			int foo(C1 c) { return 0; }
		}
		public void foo(C1 c, int i) {
			new C3().foo(c);
		}
	}
}
Then invoke "Move member type to new file" on C2...

[jdt-core internal]
Test case added in JavaSearchBugsTests
Comment 8 Maxime Daniel CLA 2005-06-16 13:25:50 EDT
The exception is gone and the refactoring 

Opened a new bug to track errors in the generated code:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=100413.

Verified using build N20050616-0010 + JDT Core HEAD.