Bug 265065 - [search] java.lang.ClassCastException while running "Refactor...Extract Class"
Summary: [search] java.lang.ClassCastException while running "Refactor...Extract Class"
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4.1   Edit
Hardware: Sun All
: P3 normal (vote)
Target Milestone: 3.5 M6   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 238282 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-02-16 17:33 EST by Adam Steiner CLA
Modified: 2009-03-09 12:01 EDT (History)
2 users (show)

See Also:


Attachments
Proposed patch (7.04 KB, patch)
2009-02-18 06:45 EST, 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 Adam Steiner CLA 2009-02-16 17:33:00 EST
I was trying to use the  "Refactor...Extract Class" feature on an internal class, and this error occurs:

-- Error Details --
Date: Mon Feb 16 17:30:35 EST 2009
Message: Internal Error
Severity: Error
Plugin: org.eclipse.ltk.ui.refactoring
Exception Stack Trace:
java.lang.reflect.InvocationTargetException
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:415)
at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.run(RefactoringWizardDialog2.java:317)
at org.eclipse.ltk.ui.refactoring.RefactoringWizard.createChange(RefactoringWizard.java:584)
at org.eclipse.ltk.ui.refactoring.RefactoringWizard.computeUserInputSuccessorPage(RefactoringWizard.java:423)
at org.eclipse.ltk.ui.refactoring.UserInputWizardPage.computeSuccessorPage(UserInputWizardPage.java:75)
at org.eclipse.ltk.ui.refactoring.UserInputWizardPage.getNextPage(UserInputWizardPage.java:115)
at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.nextOrPreviewPressed(RefactoringWizardDialog2.java:488)
at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2.access$0(RefactoringWizardDialog2.java:485)
at org.eclipse.ltk.internal.ui.refactoring.RefactoringWizardDialog2$1.widgetSelected(RefactoringWizardDialog2.java:678)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation$1.run(RefactoringWizardOpenOperation.java:144)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation.run(RefactoringWizardOpenOperation.java:156)
at org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter.activate(RefactoringStarter.java:37)
at org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter.startExtractClassRefactoring(RefactoringExecutionStarter.java:527)
at org.eclipse.jdt.ui.actions.ExtractClassAction.run(ExtractClassAction.java:140)
at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:278)
at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:250)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:583)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:500)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2382)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2346)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2198)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:493)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:488)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
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:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
at org.eclipse.equinox.launcher.Main.main(Main.java:1212)
Caused by: java.lang.ClassCastException: org.eclipse.jdt.internal.core.search.matching.OrPattern cannot be cast to org.eclipse.jdt.internal.core.search.matching.VariablePattern
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.newFieldReferenceMatch(MatchLocator.java:1409)
at org.eclipse.jdt.internal.core.search.matching.FieldLocator.matchReportReference(FieldLocator.java:223)
at org.eclipse.jdt.internal.core.search.matching.OrLocator.matchReportReference(OrLocator.java:265)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2147)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2593)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2322)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:1614)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1040)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1081)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1213)
at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:223)
at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:506)
at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:551)
at org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine.internalSearch(RefactoringSearchEngine.java:142)
at org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine.search(RefactoringSearchEngine.java:117)
at org.eclipse.jdt.internal.corext.refactoring.structure.ExtractClassRefactoring.updateReferences(ExtractClassRefactoring.java:531)
at org.eclipse.jdt.internal.corext.refactoring.structure.ExtractClassRefactoring.checkFinalConditions(ExtractClassRefactoring.java:364)
at org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:85)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:121)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1800)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Root exception:
java.lang.ClassCastException: org.eclipse.jdt.internal.core.search.matching.OrPattern cannot be cast to org.eclipse.jdt.internal.core.search.matching.VariablePattern
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.newFieldReferenceMatch(MatchLocator.java:1409)
at org.eclipse.jdt.internal.core.search.matching.FieldLocator.matchReportReference(FieldLocator.java:223)
at org.eclipse.jdt.internal.core.search.matching.OrLocator.matchReportReference(OrLocator.java:265)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2147)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2593)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching(MatchLocator.java:2322)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.process(MatchLocator.java:1614)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1040)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1081)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1213)
at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:223)
at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:506)
at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:551)
at org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine.internalSearch(RefactoringSearchEngine.java:142)
at org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine.search(RefactoringSearchEngine.java:117)
at org.eclipse.jdt.internal.corext.refactoring.structure.ExtractClassRefactoring.updateReferences(ExtractClassRefactoring.java:531)
at org.eclipse.jdt.internal.corext.refactoring.structure.ExtractClassRefactoring.checkFinalConditions(ExtractClassRefactoring.java:364)
at org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:85)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:121)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1800)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Comment 1 Frederic Fusier CLA 2009-02-17 04:06:05 EST
Would you have a small test case to help me to reproduce?
Comment 2 Adam Steiner CLA 2009-02-17 09:29:23 EST
(In reply to comment #1)
> Would you have a small test case to help me to reproduce?
> 

The scenario is this:

public class MyClass {
	/*
	 * Lots of Code here
	 * 
	 */

	private class MyPrivateClass {
		public Integer type = TYPE_A;
		public Object value = null;

		public MyPrivateClass(Integer type, Object value) {
			this.type = type;
			this.value = value;
		}

		public MyPrivateClass() {
		}
	}

	private static final Integer TYPE_A = new Integer(0);
	private static final Integer TYPE_B = new Integer(1);
	private static final Integer TYPE_C = new Integer(2);
	private static final Integer TYPE_D = new Integer(3);

	public MyClass(){		

	}
	
	/*
	 * 
	 * And lots of Code here
	 * 
	 */
}


I click on "MyPrivateClass", Refactor, Extract Class...

It gives me the dialog to Extract Class, with all the fields contained therein.  But on "Ok" or "Preview", it will throw the exception.

Now, I tried "Extract Class" on this test class, and it worked fine.  Not to be made a fool, I went back to the class in question, and pulled out a copy of the source from before I manually extracted the class.  Running "Extract Class" there fired the exception as well.

So obviously, the issue lies in the surrounding code, not with the inner class itself.  Unfortunately, I can't give you the full code, nor was I able to trim the file to a point that the error still fires.

If you have any questions about the file, then please ask, and I will try to be as helpful as possible.

Adam
Comment 3 Frederic Fusier CLA 2009-02-17 10:02:52 EST
(In reply to comment #2)
Thanks for your test case.

As the problem comes from an invalid cast of an OrPattern to VariablePattern, I assumed that in the surrounding code, you have a local variable which declaring class is the MyPrivateClass...

Based on this assumption, I tried the following snippet:

public class MyClass {

    private class MyPrivateClass {
            public Integer type = TYPE_A;
            public Object value = null;

            public MyPrivateClass(Integer type, Object value) {
                    this.type = type;
                    this.value = value;
            }

            public MyPrivateClass() {
            }
    }

    private static final Integer TYPE_A = new Integer(0);
    private static final Integer TYPE_B = new Integer(1);

    void foo (Object value) {
		MyPrivateClass mpc = new MyPrivateClass(TYPE_A, value);
		if (value == null) {
			mpc.type = TYPE_B;
		}
	}
}

and got the same exception...
Comment 4 Frederic Fusier CLA 2009-02-18 06:45:32 EST
Created attachment 126012 [details]
Proposed patch
Comment 5 Frederic Fusier CLA 2009-02-18 07:36:59 EST
Released for 3.5M6 in HEAD stream.
Comment 6 Frederic Fusier CLA 2009-03-04 09:59:35 EST
*** Bug 238282 has been marked as a duplicate of this bug. ***
Comment 7 David Audel CLA 2009-03-09 12:01:17 EDT
Verified for 3.5M6 using I20090309-0100.