Bug 302455 - java.lang.ClassCastException in secondary types removal
Summary: java.lang.ClassCastException in secondary types removal
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Linux
: P3 normal with 1 vote (vote)
Target Milestone: 3.6 M6   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-10 11:32 EST by Frederic Fusier CLA
Modified: 2010-03-10 07:38 EST (History)
8 users (show)

See Also:


Attachments
First run installing the Groovy plugin (log file 0) (9.47 KB, application/octet-stream)
2010-02-12 16:53 EST, Jörg Thönnes CLA
no flags Details
Restart and uninstall Groovy (log 1) (65.34 KB, application/octet-stream)
2010-02-12 16:54 EST, Jörg Thönnes CLA
no flags Details
Restarted and changed class file output folder (log 2) (139.30 KB, application/octet-stream)
2010-02-12 16:57 EST, Jörg Thönnes CLA
no flags Details
Restarted workspace with pure 3.6 M5 Helios (Java build) (10.70 KB, application/octet-stream)
2010-02-12 17:30 EST, Jörg Thönnes CLA
no flags Details
Proposed patch (5.95 KB, patch)
2010-02-15 11:34 EST, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Frederic Fusier CLA 2010-02-10 11:32:31 EST
+++ This bug was initially created as a clone of Bug #299746 +++

Bug 299746 comment 6 shows a separate problem while removing secondary types from the JavaModelManager cache:

> Created an attachment (id=157034) [details]
> Second stack trace after moving the .class files besides .java files

> As mentioned before, my colleague moved the .class files back to the .java
> files.
> This resulted in another stack trace.

Hence, I opened a separated bug to track this issue in the JDT/Core land...
Comment 1 Frederic Fusier CLA 2010-02-10 11:34:13 EST
In fact, what I would like to have was a trace file with the JavaModelManager
debug activated when the exception occurs... I suspect this exception to cancel the Groovy uninstall process and lead to have some files/project not to be removed properly.

So, I suggest that you execute the following scenario:
1) Start in a brand new wksp
2) Install the Groovy plugin
3) Load your projects
4) Leave the session
5) Restart the session with the JMM debug activated
6) Uninstall the Groovy plugin
7) Copy the console output in log file 1
8) Leave the session (I guess it's mandatory after the Groovy uninstall)
9) Restart the session with the JMM debug activated
10) Move the .class files besides the .java files (in fact, do the same 
    operation than you did in comment 6)
11) Copy the console output in log file 2
12) Attach the 2 log files to the bug
Comment 2 Olivier Thomann CLA 2010-02-10 11:38:55 EST
bug 299746 should be closed as a duplicate of bug 286379.
Comment 3 Andrew Eisenberg CLA 2010-02-11 17:23:21 EST
As lead developer of the Groovy-Eclipse project, I will be happy to look at this.  However, I am on leave right now for the next 5 weeks, so I can't spend much time on it.
Comment 4 Jörg Thönnes CLA 2010-02-12 16:50:56 EST
(In reply to comment #1)
> In fact, what I would like to have was a trace file with the JavaModelManager
> debug activated when the exception occurs... I suspect this exception to cancel
> the Groovy uninstall process and lead to have some files/project not to be
> removed properly.

OK, so I downloaded a fresh E3.5 SR1 copy and used a new workspace:
 
> So, I suggest that you execute the following scenario:
> 1) Start in a brand new wksp
> 2) Install the Groovy plugin
> 3) Load your projects

Using "Import existing projects..."

> 4) Leave the session
> 5) Restart the session with the JMM debug activated
> 6) Uninstall the Groovy plugin
> 7) Copy the console output in log file 1
> 8) Leave the session (I guess it's mandatory after the Groovy uninstall)
> 9) Restart the session with the JMM debug activated
> 10) Move the .class files besides the .java files (in fact, do the same
> operation than you did in comment 6)

Since I did not do it myself, I can only guess the steps my colleague made:

Configure build path and set the output folder for .class files from "all-macd/target/classes"
back to "all-macd/src". Now the .class files are in the same directory ("besides") as the .java or .groovy files.

But in this case no exception occured.

> 11) Copy the console output in log file 2
> 12) Attach the 2 log files to the bug

Will do in a moment.
Comment 5 Jörg Thönnes CLA 2010-02-12 16:53:28 EST
Created attachment 159042 [details]
First run installing the Groovy plugin (log file 0)

This is not your log file 1, but log file 0.
Comment 6 Jörg Thönnes CLA 2010-02-12 16:54:56 EST
Created attachment 159043 [details]
Restart and uninstall Groovy (log 1)

This is the first log you requested: Restarted workspace with debug/javamodel=true and un-installed Groovy plugin.
Comment 7 Jörg Thönnes CLA 2010-02-12 16:57:11 EST
Created attachment 159044 [details]
Restarted and changed class file output folder (log 2)

This is your log 2. After restarting, I changed the project output folder for class files from "target/classes"
to "src".

Finally, I did the rename refactoring which used to fail. Now it worked.
Comment 8 Jörg Thönnes CLA 2010-02-12 17:30:20 EST
Created attachment 159046 [details]
Restarted workspace with pure 3.6 M5 Helios (Java build)

After having re-installed the Groovy plugin by reverting to previous configuration and moving the output folder back to "target/classes",
I left Eclipse and restarted with a freshly downloaded Eclipse 3.6 M5 Java build. Of course, this one did not contain any Groovy plugin.

And now the rename failed with the attached exception 

java.lang.ClassCastException: java.lang.String cannot be cast to org.eclipse.jdt.internal.core.JavaElement
    at org.eclipse.jdt.internal.core.JavaModelManager.secondaryTypesRemoving(JavaModelManager.java:4439)
    at org.eclipse.jdt.internal.core.JavaModelManager.secondaryTypesRemoving(JavaModelManager.java:4370)

There has been a patch in this area referenced by the other bug closed as duplicate.

Is it this kind of error you are looking for?
Comment 9 Olivier Thomann CLA 2010-02-12 18:07:03 EST
Yes, this is the one I'd like to be able to debug.
If you have any idea how I can reproduce this one myself, this would be really helpful.
Comment 10 Frederic Fusier CLA 2010-02-15 06:02:45 EST
(In reply to comment #8)
> Created an attachment (id=159046) [details]
> Restarted workspace with pure 3.6 M5 Helios (Java build)
> 
Thanks for the trace, it was really helpful. I think I got the reason of this failure... I'll attach a patch soon.
Comment 11 Frederic Fusier CLA 2010-02-15 11:34:31 EST
Created attachment 159118 [details]
Proposed patch

There was a hole while building the secondary types caches allowing invalid entry values in the map, typically when indexes contain types which do no longer have a valid extension...

I also the fixed the potential issue when removing a file extension, the secondary types caches need to be flushed to avoid keeping obsolete secondary types in the caches...
Comment 12 Frederic Fusier CLA 2010-02-15 11:38:11 EST
Note that closing and reopen the project(s) should fix the current issue even in the existing workspace as this both flush the secondary types caches and the index file...
Comment 13 Frederic Fusier CLA 2010-02-15 15:23:17 EST
(In reply to comment #11)
> Created an attachment (id=159118) [details]
> Proposed patch
> 
Released for 3.6M6 in HEAD stream.
Comment 14 Jörg Thönnes CLA 2010-02-15 16:36:33 EST
Hello Frederic,

thanks for the quick patch. I really do appreciate this fast solution.
Will we and the Groovy people benefit from this patch and the other other one:
bug 286379 ( [search] Problem while searching class) in the 3.5 SR2 release?
This would be wonderful.

Thanks, Jörg
Comment 15 Dani Megert CLA 2010-02-16 03:53:17 EST
>Will we and the Groovy people benefit from this patch and the other other one:
>bug 286379 ( [search] Problem while searching class) in the 3.5 SR2 release?
No. 3.5.2 is basically done and this bug here is in Eclipse since at least 3.4.
Comment 16 Jörg Thönnes CLA 2010-02-16 04:12:35 EST
(In reply to comment #15)
> >Will we and the Groovy people benefit from this patch and the other other one:
> >bug 286379 ( [search] Problem while searching class) in the 3.5 SR2 release?
> No. 3.5.2 is basically done and this bug here is in Eclipse since at least 3.4.

That's a pity since this issue effectively restricts the useability of the Groovy plugin in the same way as bug 286379 ([search] Problem while searching class) does it.

Frederic, would it be possible to provide a point patch JAR file for both bugs to be applied to our local installation?
I would be happy to test it and provide it to the Groovy people if it works.

Many thanks, Jörg
Comment 17 Frederic Fusier CLA 2010-02-16 04:49:04 EST
(In reply to comment #16)
> (In reply to comment #15)
> > >Will we and the Groovy people benefit from this patch and the other other one:
> > >bug 286379 ( [search] Problem while searching class) in the 3.5 SR2 release?
> > No. 3.5.2 is basically done and this bug here is in Eclipse since at least 3.4.
> 
> That's a pity since this issue effectively restricts the useability of the
> Groovy plugin in the same way as bug 286379 ([search] Problem while searching
> class) does it.
> 
> Frederic, would it be possible to provide a point patch JAR file for both bugs
> to be applied to our local installation?
> I would be happy to test it and provide it to the Groovy people if it works.
> 
> Many thanks, Jörg

You can do it by yourself really easily... Just check-out the JDT/Core code of R3_5_maintenance stream from the dev.eclipse.org, apply both patches attached to the bugs and run the org.eclipse.jdt.core/script/exportplugin.xml as Ant Build... Then, rename the produced jar file with the same name than the one installed in your eclipse plugins dir (it should be org.eclipse.jdt.core_3.5.1.v_972_R35x.jar if you use 3.5.1) and restart your eclipse session with -clean argument on the command line... Of course, it would be a good idea to save the original 3.5.1 JDT/Core jar file in case you want to revert the patch...

However, if this is true that the patch JAR is necessary for bug 286379, for this bug, as I said in comment 12, there's a really simple workaround: just close your projects and reopen them. This should flush the secondary types cache and the index file and then you should not face this issue again.

Note also that the issue described in this bug only happens after having removed the Groovy plugin which adds an extension point for content type. It should work while this plugin is still activated, the problem only occurs after you did investigate the initial issue and remove the plugin. Hence, it's not true that it restricts the Groovy plugin usability...
Comment 18 Frederic Fusier CLA 2010-02-16 04:53:10 EST
(In reply to comment #17)
> However, if this is true that the patch JAR is necessary for bug 286379, for
> this bug, as I said in comment 12, there's a really simple workaround: just
> close your projects and reopen them. This should flush the secondary types
> cache and the index file and then you should not face this issue again.
> 
Sorry, I was wrong, a new jar File is NOT necessary for bug 286379... The proposed workaround for this bug 302455 will also work for the bug 286379 issue: close all projects and reopen them in the workspace.

Hence, this is definitely not fixes we will backport to the 3.5 maintenance stream.
Comment 19 Jörg Thönnes CLA 2010-02-16 05:28:22 EST
Now I am got a bit puzzled:

I understood that the workaround for both bugs, ie.  bug 286379/bug 299746 and bug 302455 is just to close and open the affected projects.

But I am afraid that the original issue, ie. that renaming constantly fails if the Groovy plugin is installed cannot be cured by just re-opening the project. And I definitely do not want to re-open the project before each rename refactoring :-)

Please give me a hint were I am wrong: Does this mean that there is also a bug in the Groovy plugin?

Many thanks for your help so far, Jörg
Comment 20 Frederic Fusier CLA 2010-02-16 07:53:34 EST
(In reply to comment #19)
> Now I am got a bit puzzled:
> 
> I understood that the workaround for both bugs, ie.  bug 286379/bug 299746 and
> bug 302455 is just to close and open the affected projects.
> 
> But I am afraid that the original issue, ie. that renaming constantly fails if
> the Groovy plugin is installed cannot be cured by just re-opening the project.
> And I definitely do not want to re-open the project before each rename
> refactoring :-)
> 
> Please give me a hint were I am wrong: Does this mean that there is also a bug
> in the Groovy plugin?
> 
> Many thanks for your help so far, Jörg

To be precise, I just said that the workaround works to get rid of bug 286379 and this bug (i.e. bug 302455) issues. The bug 299746 issue (ie. the stack overflow error) is a problem with the Groovy plugin (I've changed the bug status to make this clearer, see bug 299746 comment 42...), hence there's nothing else we can do from our side.

I hope this is clear now :-)
Comment 21 Jörg Thönnes CLA 2010-02-16 08:53:32 EST
(In reply to comment #20)
> (In reply to comment #19)
> > Now I am got a bit puzzled:
> [...]
> I hope this is clear now :-)

Thank you very much, these clarification did help me a lot.
There is already a Groovy plugin issue

GRECLIPSE-642: Groovy plugin may break JDT rename feature completely
http://jira.codehaus.org/browse/GRECLIPSE-642

and I will report your findings there.

Thanks again for your help!

A+ Jörg
Comment 22 Olivier Thomann CLA 2010-03-09 15:32:38 EST
Jörg, could you please verify that you no longer get the problem with one of the latest I-build ?

Closing as VERIFIED for the verification process.
Please report here once the verification is done.
Thanks.
Comment 23 Jörg Thönnes CLA 2010-03-10 07:38:22 EST
(In reply to comment #22)
> Jörg, could you please verify that you no longer get the problem with one of the
> latest I-build ?

Olivier, I am sorry but I would need this patch for Eclipse 3.5 to verify it. The GRECLIPSE
version 2.0.0Release which I need to verify this behaviour does not work with 3.6 Helios.

The recent GRECLIPSE dev builds also works with 3.6, but also includes patches for the above GRECLIPSE
issue

GRECLIPSE-642: Groovy plugin may break JDT rename feature completely
http://jira.codehaus.org/browse/GRECLIPSE-642

so I am not sure if I can reproduce this.

Will try something next week.