Bug 204679 - Show Annotation on old revision of .java file leaks CompilationUnitEditor
Summary: Show Annotation on old revision of .java file leaks CompilationUnitEditor
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Team (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.4 M6   Edit
Assignee: Tomasz Zarna CLA
QA Contact:
URL:
Whiteboard: hasPatch
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-26 09:25 EDT by Markus Keller CLA
Modified: 2008-03-27 08:46 EDT (History)
2 users (show)

See Also:


Attachments
Temporary fix (870 bytes, patch)
2007-09-26 09:27 EDT, Markus Keller CLA
no flags Details | Diff
Fix without creating any editor (3.99 KB, patch)
2007-09-27 13:29 EDT, Dani Megert CLA
no flags Details | Diff
Fix which only creates editor if needed (2.03 KB, patch)
2007-10-03 06:27 EDT, Dani Megert CLA
no flags Details | Diff
Fix which only creates editor if needed (7.99 KB, patch)
2007-10-03 09:12 EDT, Dani Megert CLA
no flags Details | Diff
Dani's latest patch with an additional null check (8.03 KB, patch)
2008-02-05 06:11 EST, Tomasz Zarna CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2007-09-26 09:25:37 EDT
I20070925-1406

In History view for a .java file from CVS, select an old revision and choose context menu > Show Annotation. Close the editor.

=> A CompilationUnitEditor is leaked (via JavaEditorErrorTickUpdater and via AbstractTextEditor$PropertyChangeListener).

The reason is that org.eclipse.team.internal.ui.Utils.isTextEditor(IEditorDescriptor) uses internal ui.workbench code to create an editor but does not dispose it afterwards.

I don't think you should wait for bug 99568. A better request would be a query on IEditorDescriptor that returns the Class object that would be used to create an editor instance. The check can then use Class.isAssignableFrom(Class) without creating the editor at all.
Comment 1 Markus Keller CLA 2007-09-26 09:27:42 EDT
Created attachment 79201 [details]
Temporary fix

Fixes the leak until a better solution is available.
Comment 2 Dani Megert CLA 2007-09-27 13:29:11 EDT
Created attachment 79299 [details]
Fix without creating any editor

This fix also removes the usage access restricted code. If you want to keep on using access restricted code you can make the fix simpler as the EditorDescriptor already has the class and bundle name.

I decided to make the util method easier to use by directly handling the exception case inside it.

Also, this code could be sent over to Platform UI should they decide to provide such a helper in the future.
Comment 3 Markus Keller CLA 2007-09-28 08:18:25 EDT
(In reply to comment #2)

Caveat: the "Fix without creating any editor" probably fails for clients that supply an IExecutableExtensionFactory for creating the instance, see Javadoc of org.eclipse.core.runtime.IConfigurationElement.createExecutableExtension(String).

> Also, this code could be sent over to Platform UI should they decide to provide
> such a helper in the future.

I think the right final home for the registry reading and class loading would be org.eclipse.core.runtime.IConfigurationElement, e.g.:
public Class createExtensionClass(String propertyName) throws CoreException;

This method would have to specify what happens in the IExecutableExtensionFactory case (whether it just always fails, or whether we need new API in IExecutableExtensionFactory to create just the Class but not an instance).
Comment 4 Michael Valenta CLA 2007-09-28 10:42:29 EDT
I have released the patch from comment 1 since it does fix the problem and is guaranteed not to cause a regression. However, I like the idea of not needing to create the editor to determine if it is a text editor. In practice, do we know if editors are often registered vi an IExecutableExtensionFactory?
Comment 5 Dani Megert CLA 2007-10-03 06:27:59 EDT
Created attachment 79622 [details]
Fix which only creates editor if needed

> In practice, do we know if editors are often registered vi an 
>IExecutableExtensionFactory?
We don't know how often but I can check whether the given 'class' does so. Here's a patch that fixes this and has less changes as it takes the necessary attributes from the internal EditorDescriptor class.
Comment 6 Markus Keller CLA 2007-10-03 08:27:42 EDT
(In reply to comment #5)
I have not tried it, but from looking at the patch, I think it will fail too if the class attribute uses IExecutableExtensionFactory as suggested in the Javadoc, e.g. class="p.MyExecutableExtensionFactory:pinkTextEditor". See the code around prop.indexOf(':') in ConfigurationElement.createExecutableExtension(String).

I think you should also try to create (and dispose) the editor in case of a ClassNotFoundException.
Comment 7 Dani Megert CLA 2007-10-03 08:34:27 EDT
>I think you should also try to create (and dispose) the editor in case of a
>ClassNotFoundException.
I wouldn't do that. Simply check the class string for a ':'.
Comment 8 Markus Keller CLA 2007-10-03 08:56:56 EDT
Note that ConfigurationElement.createExecutableExtension(String) contains even more special stuff (e.g. trimming of the strings, a contributorName, or a definition in a separate child element). 

I agree with the shortcut for the simplest case (which the SDK uses exclusively), but I would defer everything else to createExecutableExtension until Core has better support for this.

Even if you decide to add the ":" case, I'd argue that it is not normal that a class cannot be found, and chances are much higher that our hand-made shortcut is incomplete than that there's really something wrong with the contribution.
Comment 9 Dani Megert CLA 2007-10-03 09:12:17 EDT
Created attachment 79629 [details]
Fix which only creates editor if needed

OK. I give up ;-)
Here's a more pessimistic patch that also handles the 1 in a million case where such a factory is used (I'd even say there's none out there).
Comment 10 Dani Megert CLA 2007-12-04 05:05:49 EST
The patch is not that big, maybe still for M4? ;-)
Comment 11 Tomasz Zarna CLA 2007-12-04 05:45:40 EST
Dani, I'm busy with some other items, so I can't promise you I will take a look at it before M4... but I will try.
Comment 12 Dani Megert CLA 2007-12-04 06:15:28 EST
Thanks.
Comment 13 Tomasz Zarna CLA 2008-02-05 06:11:12 EST
Created attachment 88867 [details]
Dani's latest patch with an additional null check

This is Daniel's patch with an additional null check, despite the fact the null shouldn't be returned as the editor descriptor gives us the plug-in name. I will release the patch as the first one for 3.4 M6. Sorry for the delay Daniel.
Comment 14 Tomasz Zarna CLA 2008-02-11 04:04:54 EST
The latest patch released to HEAD. Thanks Dani.
Comment 15 Tomasz Zarna CLA 2008-03-27 08:46:47 EDT
Verified by code inspection.