Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 268574

Summary: [exceptions] Very frequent ClassCastExceptions: CompilationUnit
Product: [WebTools] JSDT Reporter: Jens Beyer <jens.beyer>
Component: GeneralAssignee: Nitin Dahyabhai <thatnitind>
Status: RESOLVED FIXED QA Contact: Nitin Dahyabhai <thatnitind>
Severity: normal    
Priority: P2 CC: cmjaun, itewksbu, mamacdon, raghunathan.srinivasan, vlad.balan
Version: 3.0.4Flags: thatnitind: pmc_approved? (david_williams)
raghunathan.srinivasan: pmc_approved+
thatnitind: pmc_approved? (naci.dai)
thatnitind: pmc_approved? (deboer)
thatnitind: pmc_approved? (neil.hauge)
thatnitind: pmc_approved? (kaloyan)
thatnitind: review+
Target Milestone: 3.2.3   
Hardware: PC   
OS: Windows XP   
Whiteboard: PMC_approved
Attachments:
Description Flags
Requestes sample projects
none
Fix Patch none

Description Jens Beyer CLA 2009-03-13 13:33:58 EDT
Build ID: M20080911-1700

Steps To Reproduce:
java.lang.ClassCastException: org.eclipse.wst.jsdt.internal.core.CompilationUnit
at org.eclipse.wst.jsdt.internal.core.builder.AbstractImageBuilder.acceptResult(AbstractImageBuilder.java:139)
at org.eclipse.wst.jsdt.internal.compiler.Compiler.compile(Compiler.java:362)
at org.eclipse.wst.jsdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:311)
at org.eclipse.wst.jsdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:168)
at org.eclipse.wst.jsdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:248)
at org.eclipse.wst.jsdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:58)
at org.eclipse.wst.jsdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:291)
at org.eclipse.wst.jsdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:194)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:633)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:170)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:201)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:253)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:256)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:309)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:341)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:140)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:238)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

Not marking as minor since I don't know if there's functionality affected/not available due to that bug or if it is just cosmetic.

More information:
WTP 3.0.4, .js files spread over some RCP plug-ins containing also Java code.

It happens everytime the "builder" runs - after saving a resource, and when cleaning/rebuilding.

The error is shown on the java console of Eclipse (started eclipsec.exe), and in the Error log, but it is not popping up a dialog.
Comment 1 Chris Jaun CLA 2009-03-16 17:21:12 EDT
Can you provide any additional details on your project set up or provide a small sample project where this is reproducible?

I haven't been able to cause this exception to take place yet.

Did the log mention what type of object it was attempting to cast from?

The line in question is: SourceFile compilationUnit = (SourceFile) result.getCompilationUnit();
Comment 2 Jens Beyer CLA 2009-03-17 06:33:59 EDT
Created attachment 129060 [details]
Requestes sample projects

As requested, find attached two plug-in projects. I created them from scratch in a completely new workspace (just to make sure I didn't mess something up with the workspace) and the exception occured as soon as I added the Javascript library folder of test as library folder in test1 (referenced projects, so to speak).

I have to do that in order to be able to use functions from test in test1. I didn't find any other way to do such.
Comment 3 Chris Jaun CLA 2009-03-31 17:14:08 EDT
I am able to reproduce this now. Thanks for the sample projects.

It does have something to do with setting up the library folder.

Still investigating...
Comment 4 Chris Jaun CLA 2009-09-15 11:55:49 EDT
Categorizing JSDT bugzillas for planning purposes.
Comment 5 Chris Jaun CLA 2010-07-01 15:32:52 EDT
*** Bug 318203 has been marked as a duplicate of this bug. ***
Comment 6 Chris Jaun CLA 2010-07-01 15:33:15 EDT
Steps to Reproduce:
1. create 2 js projects, with 2 js files, each with one function.
2. make one project reference the other through "include path"
3. in the including project's function call the other function, from the
included project. save the file.
Comment 7 Ian Tewksbury CLA 2011-01-21 16:58:53 EST
Created attachment 187333 [details]
Fix Patch

The issue here is the Compilers check for weather it should compile a referenced ICompUnit is wrong.  It should be checking if the referenced ICompuUnit is a SourceFile and only then try to compile it.

Simple one line fix.  Passes all existing JUnits.
Comment 8 Nitin Dahyabhai CLA 2011-01-26 17:53:02 EST
* Explain why you believe this is a stop-ship defect. Or, if it is a "hotbug" (requested by an adopter) please document it as such. 

The compiler breaks its processing when this CCE happens.  It doesn't forget that it needs to "compile" the original source file that triggered the problem, though, so it will continue to try and fail to compile it properly.

* Is there a work-around? If so, why do you believe the work-around is insufficient? 

No workaround if the project setup is as required.

* How has the fix been tested? Is there a test case attached to the bugzilla record? Has a JUnit Test been added? 

Ad-hoc testing.

* Give a brief technical overview. Who has reviewed this fix? 

Completing the bindings for a type reference adds all of the compilation units containing it into the list of units to process.  The casting to a source unit completes the actual compilation process by storing the generated errors as markers, but there's no need to do that for the units added incidentally to complete bindings.  They would be processed as proper source units on their own at another time (at which point they'll cause other units to be loaded for their sake).

* What is the risk associated with this fix? 

Low.  It adds an instanceof check before adding actual source units to the more involved compiling queue.
Comment 9 Nitin Dahyabhai CLA 2011-01-26 22:33:10 EST
Released.