Bug 296629

Summary: [quick fix] Cast quick fix not offered for method-local classes
Product: [Eclipse Project] JDT Reporter: Remy Suen <remy.suen>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: amj87.iitr, daniel_megert, markus.kell.r, Olivier_Thomann, srikanth_sankaran
Version: 3.6   
Target Milestone: 3.6 M4   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed fix
none
Proposed fix + regression test none

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.