Bug 140980 - [recovery] ClassCastException from JDT compiler
Summary: [recovery] ClassCastException from JDT compiler
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.3 M4   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 145459 158029 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-05-10 01:28 EDT by Brock Janiczak CLA
Modified: 2007-01-09 09:30 EST (History)
4 users (show)

See Also:


Attachments
Proposed fix (19.87 KB, patch)
2006-11-13 05:43 EST, David Audel CLA
no flags Details | Diff
Possible fix fo 3.2 (9.28 KB, patch)
2006-11-13 05:48 EST, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brock Janiczak CLA 2006-05-10 01:28:51 EDT
Version: 3.2.0
Build id: I20060223-1656

I found several of the attached exceptions in my log.  No error dialog was displayed and i do not have any steps to reproduce

java.lang.ClassCastException: org.eclipse.jdt.internal.compiler.ast.TypeDeclaration cannot be cast to org.eclipse.jdt.internal.compiler.ast.Block
    at org.eclipse.jdt.internal.compiler.parser.Parser.consumeStatementTry(Parser.java:6825)
    at org.eclipse.jdt.internal.compiler.parser.Parser.consumeRule(Parser.java:5410)
    at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:8852)
    at org.eclipse.jdt.internal.compiler.parser.Parser.parseStatements(Parser.java:9322)
    at org.eclipse.jdt.internal.compiler.parser.Parser$1$MethodVisitor.endVisitMethod(Parser.java:9589)
    at org.eclipse.jdt.internal.compiler.parser.Parser$1$MethodVisitor.endVisit(Parser.java:9575)
    at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:216)
    at org.eclipse.jdt.internal.compiler.parser.Parser.recoverStatements(Parser.java:9680)
    at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:8896)
    at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:9165)
    at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.parseStatements(MethodDeclaration.java:117)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.parseMethod(TypeDeclaration.java:854)
    at org.eclipse.jdt.internal.compiler.parser.Parser.getMethodBodies(Parser.java:8111)
    at org.eclipse.jdt.internal.compiler.SourceElementParser.parseCompilationUnit(SourceElementParser.java:1416)
    at org.eclipse.jdt.internal.core.CompilationUnit.buildStructure(CompilationUnit.java:132)
    at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:229)
    at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:503)
    at org.eclipse.jdt.internal.core.CompilationUnit.makeConsistent(CompilationUnit.java:975)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:131)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:71)
    at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:720)
    at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:779)
    at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1102)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:97)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:82)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:145)
    at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(CompositeReconcilingStrategy.java:86)
    at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:94)
    at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:75)
    at org.eclipse.jdt.internal.ui.text.JavaReconciler.process(JavaReconciler.java:339)
    at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:204)
Comment 1 Frederic Fusier CLA 2006-05-10 02:49:07 EDT
Many changes have been done in compiler since your build (post 3.2 M5).
May you retry with a more recent one, 3.2 RC3 and let us know if this problem still occurs?
Thanks
Comment 2 David Audel CLA 2006-05-10 09:21:06 EDT
I can reproduce the problem with build N20060510-0010 and this test case:
public class X {
  void foo() {
    #
    try {
      System.out.println(); 
    } catch (Exception e) {
    }
    class Z {}
  }
}


The problem seems to be in statements recovery
Comment 3 Philipe Mulet CLA 2006-05-10 09:37:25 EDT
+1 for 3.2RC4, since regression over 3.1 (where was no statement recovery)
Comment 4 Philipe Mulet CLA 2006-05-10 09:43:33 EDT
If fix is too involving, might be better to address in 3.2.1/3.3... and only do the minimum here to address ClassCastException...
Comment 5 David Audel CLA 2006-05-11 04:37:20 EDT
Another test case:
public class X {
  void foo() {
    #
    try {
      System.out.println(); 
    } catch (Exception e) {
      class Z {}
    }
  }
}
Comment 6 Philipe Mulet CLA 2006-05-11 06:30:34 EDT
Deferring, as early investigation is proving to be too risk for a RC4 fix.
Comment 7 David Audel CLA 2006-06-06 04:46:18 EDT
*** Bug 145459 has been marked as a duplicate of this bug. ***
Comment 8 Philipe Mulet CLA 2006-08-30 05:05:38 EDT
This PR was tentatively tagged for 3.2.1, but the problem is tricky and more general than this very testcase, and a real fix should be investigated during 3.3.

Possibly, we will backport a fix to a 3.2 maintenance stream (either official or unofficial - patch).
Removing 3.2.1 tag for current time being.
Comment 9 David Audel CLA 2006-09-21 10:49:19 EDT
*** Bug 158029 has been marked as a duplicate of this bug. ***
Comment 10 David Audel CLA 2006-11-13 05:43:32 EST
Created attachment 53736 [details]
Proposed fix
Comment 11 David Audel CLA 2006-11-13 05:47:11 EST
Released for 3.3 M4.

Tests added
  DietRecoveryTest#test117_2()
  DietRecoveryTest#test120() -> test123()
Comment 12 David Audel CLA 2006-11-13 05:48:13 EST
Created attachment 53737 [details]
Possible fix fo 3.2
Comment 13 David Audel CLA 2006-11-13 06:47:25 EST
Reopen for 3.2.2 investigation.
Comment 14 Philipe Mulet CLA 2007-01-09 04:48:01 EST
Removing 3.2.2 commitment, fix is not trivial, and released late for 3.3M4 inclusion. Need more exercizing.
Comment 15 Frederic Fusier CLA 2007-01-09 09:30:08 EST
Verified for 3.3 M4 using build I20061214-1445.