Bug 207573 - [1.5][compiler] Internal compiler error: ClassCastException / ArrayBinding
Summary: [1.5][compiler] Internal compiler error: ClassCastException / ArrayBinding
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 blocker (vote)
Target Milestone: 3.3.2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-26 09:18 EDT by William CLA
Modified: 2007-12-11 12:06 EST (History)
3 users (show)

See Also:
philippe_mulet: pmc_approved+


Attachments
Possible patch (3.98 KB, patch)
2007-10-30 07:24 EDT, Philipe Mulet CLA
no flags Details | Diff
Patch for 3.3.x (10.70 KB, patch)
2007-11-02 10:21 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description William CLA 2007-10-26 09:18:50 EDT
Build ID: M20070921-1145

Steps To Reproduce:
1. Create new (java) project
2. Create new class in project named Test
3. Insert code below
public class Test {
    public final <E extends Exception> E throwE (E ex, Object ... args) throws E {
        Object [] oar = new Object [0];
        return throwE (oar, ex, args);
    }
    public final <E extends Exception> E throwE (Object[] oar, E ex, Object ... args) throws E {
        throw ex;
    }
}

4. Build Project.
5. Instead of actual compilation errors in the source it shows on error on the first line. Note that this is an condensed piece of code from a source that compiles with SUN JDK 5 compiler, and that did not compile with Eclipse compiler; I ripped almost everything so that only this remained.

More information:
Stackdump:
Internal compiler error java.lang.ClassCastException: 
 org.eclipse.jdt.internal.compiler.lookup.ArrayBinding at 
 org.eclipse.jdt.internal.compiler.lookup.Scope.substitute(Scope.java:202) at 
 org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.<init>(Parameterized
 GenericMethodBinding.java:307) at 
 org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createParameterizedGenericMethod(Lo
 okupEnvironment.java:717) at 
 org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.inferFromArgumentTy
 pes(ParameterizedGenericMethodBinding.java:175) at 
 org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.computeCompatibleMe
 thod(ParameterizedGenericMethodBinding.java:56) at 
 org.eclipse.jdt.internal.compiler.lookup.Scope.computeCompatibleMethod(Scope.java:428) at 
 org.eclipse.jdt.internal.compiler.lookup.Scope.findMethod(Scope.java:1122) at 
 org.eclipse.jdt.internal.compiler.lookup.Scope.getImplicitMethod(Scope.java:1784) at 
 org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:416) at 
 org.eclipse.jdt.internal.compiler.ast.ReturnStatement.resolve(ReturnStatement.java:216) at 
 org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMetho
 dDeclaration.java:429) at 
 org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java
 :196) at 
 org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaratio
 n.java:400) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:
 1085) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1164) 
 at 
 org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.
 java:366) at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:623) at 
 org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:392) at 
 org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:362) 
 at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:173) at 
 org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:299) 
 at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:59) at 
 org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:269) at 
 org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:177) at 
 org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:624) at 
 org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37) at 
 org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:166) at 
 org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:197) at 
 org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:246) at 
 org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37) at 
 org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:249) at 
 org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:214) at 
 org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:353) at 
 org.eclipse.core.internal.resources.Project.internalBuild(Project.java:494) at 
 org.eclipse.core.internal.resources.Project.build(Project.java:75) at 
 org.eclipse.ui.actions.BuildAction.invokeOperation(BuildAction.java:194) at 
 org.eclipse.ui.actions.WorkspaceAction.execute(WorkspaceAction.java:141) at 
 org.eclipse.ui.actions.WorkspaceAction$1.runInWorkspace(WorkspaceAction.java:460) at 
 org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:38) at 
 org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Comment 1 Olivier Thomann CLA 2007-10-26 10:23:16 EDT
Reproduced with HEAD.
Added disabled regression test in org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest#_test1206
Comment 2 Philipe Mulet CLA 2007-10-30 07:16:07 EDT
Problem comes from an attempt to substitute a poor method candidate incorrectly (E for Object[] inside a ReferenceBinding[] boom!).

The poor candidate is eliminated later on, hence this is still correct code which is mishandled by the compiler.

Comment 3 Philipe Mulet CLA 2007-10-30 07:17:30 EDT
As a workaround (since blocker), you may want to rename one of the 2 methods 'throwE'; e.g.

public class Test {
    public final <E extends Exception> E throwE2 (E ex, Object ... args) throws
E {
        Object [] oar = new Object [0];
        return throwE (oar, ex, args);
    }
    public final <E extends Exception> E throwE (Object[] oar, E ex, Object ...
args) throws E {
        throw ex;
    }
}

Working on a fix.
Comment 4 Philipe Mulet CLA 2007-10-30 07:24:10 EDT
Created attachment 81570 [details]
Possible patch

Not convinced this is the best fix, however it is quite safe.
Other approach would be to simply use TypeBinding[] instead of ReferenceBinding[] for thrown exceptions list... need to see the benefits.
Comment 5 Philipe Mulet CLA 2007-10-30 12:32:06 EDT
Added GenericTypeTest#test1206-1210
Comment 6 Philipe Mulet CLA 2007-11-02 07:27:27 EDT
Released for 3.4M4.
Fixed
Comment 7 Philipe Mulet CLA 2007-11-02 07:28:15 EDT
Fixed
Comment 8 Philipe Mulet CLA 2007-11-02 10:21:26 EDT
Created attachment 81958 [details]
Patch for 3.3.x
Comment 9 Philipe Mulet CLA 2007-11-02 10:22:54 EDT
Patch also released for 3.3.2.
Comment 10 Jerome Lanneluc CLA 2007-11-22 10:34:48 EST
Fix is trivial, symptoms are bad.
Comment 11 Philipe Mulet CLA 2007-11-23 09:20:25 EST
+1 for 3.3.2
Comment 12 Kent Johnson CLA 2007-12-11 12:06:55 EST
Verified for 3.4M4 using build I20071210-1800.