Bug 296629 - [quick fix] Cast quick fix not offered for method-local classes
Summary: [quick fix] Cast quick fix not offered for method-local classes
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.6 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-01 15:51 EST by Remy Suen CLA
Modified: 2009-12-08 03:17 EST (History)
5 users (show)

See Also:


Attachments
Proposed fix (1.45 KB, patch)
2009-12-02 12:51 EST, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + regression test (3.46 KB, patch)
2009-12-02 13:30 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Remy Suen CLA 2009-12-01 15:51:30 EST
The code below will not compile because 'get()' returns an Object. However, when I use Ctrl+1, it doesn't offer a cast quick fix. :(

public class Test {
  public void v() {
     class Test2 {}
     Test2 t = get();
     t.toString();
  }

  public Object get() {return null;}
}
Comment 1 Markus Keller CLA 2009-12-02 09:09:33 EST
In HEAD, I get the NPE below. Works fine in 3.5.1.

java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.TypeBinding.isReifiable(TypeBinding.java:868)
	at org.eclipse.jdt.internal.compiler.ast.Expression.checkUnsafeCast(Expression.java:524)
	at org.eclipse.jdt.internal.compiler.ast.Expression.checkCastTypesCompatibility(Expression.java:486)
	at org.eclipse.jdt.core.dom.TypeBinding.isCastCompatible(TypeBinding.java:1009)
	at org.eclipse.jdt.internal.ui.text.correction.TypeMismatchSubProcessor.addTypeMismatchProposals(TypeMismatchSubProcessor.java:134)
	at org.eclipse.jdt.internal.ui.text.correction.QuickFixProcessor.process(QuickFixProcessor.java:311)
	at org.eclipse.jdt.internal.ui.text.correction.QuickFixProcessor.getCorrections(QuickFixProcessor.java:249)
	at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor$SafeCorrectionCollector.safeRun(JavaCorrectionProcessor.java:375)
	at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor$SafeCorrectionProcessorAccess.run(JavaCorrectionProcessor.java:337)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor$SafeCorrectionProcessorAccess.process(JavaCorrectionProcessor.java:333)
	at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor.collectCorrections(JavaCorrectionProcessor.java:462)
	at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor.collectProposals(JavaCorrectionProcessor.java:278)
	at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor.computeQuickAssistProposals(JavaCorrectionProcessor.java:240)
	at org.eclipse.jface.text.quickassist.QuickAssistAssistant$ContentAssistProcessor.computeCompletionProposals(QuickAssistAssistant.java:73)
	at org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals(ContentAssistant.java:1834)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals(CompletionProposalPopup.java:557)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$16(CompletionProposalPopup.java:554)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup$2.run(CompletionProposalPopup.java:489)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
...
Comment 2 Olivier Thomann CLA 2009-12-02 12:51:27 EST
Created attachment 153625 [details]
Proposed fix

I'll add a specific regression test.
Comment 3 Olivier Thomann CLA 2009-12-02 13:30:18 EST
Created attachment 153636 [details]
Proposed fix + regression test

Same patch with a regression test.
Comment 4 Olivier Thomann CLA 2009-12-02 13:32:50 EST
Released for 3.6M4.
Added regression test in org.eclipse.jdt.core.tests.dom.ASTConverterTestAST3_2#test0718
Comment 5 Ayushman Jain CLA 2009-12-08 02:00:23 EST
Verified for 3.6M4 using build I20091207-1800.