Bug 406994 - [implementation] ClassCastException in HyperlinkDetectorDescriptor 102, if CustomHyperlinkDetector implements IHyperlinkDetector but does not extend AbstractHyperlinkDetector
Summary: [implementation] ClassCastException in HyperlinkDetectorDescriptor 102, if Cu...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.2.1   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: 4.4 M1   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2013-05-01 11:12 EDT by Thomas Neumeier CLA
Modified: 2013-06-20 09:32 EDT (History)
4 users (show)

See Also:


Attachments
TestProject to reproduce the bug (2.93 KB, application/zip)
2013-05-01 16:01 EDT, Thomas Neumeier CLA
no flags Details
Fix (5.63 KB, patch)
2013-05-02 03:20 EDT, Dani Megert CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Neumeier CLA 2013-05-01 11:12:37 EDT
The workaround is as simple as adding "extends AbstractHyperlinkDetector" to the class definition. But this should either be fixed or at least be mentioned in the IHyperlinkDetector Interface.
Comment 1 Thomas Neumeier CLA 2013-05-01 11:22:42 EDT
The exception is thrown, when links are to be shown; Holding ctrl and moving the mouse over the editor.
Comment 2 Dani Megert CLA 2013-05-01 14:32:19 EDT
> CustomHyperlinkDetector

There is no such class in the Eclipse SDK.

See also http://www.eclipse.org/eclipse/platform-text/development/bug-incomplete.htm
Comment 3 Thomas Neumeier CLA 2013-05-01 16:01:24 EDT
Created attachment 230361 [details]
TestProject to reproduce the bug

To reproduce the bug:
1. Import the plugin project attached
2. Launch Eclipse with the imported plugin in a new (or existing) workspace
3. Open or create any textfile (Tested with files ending in txt, java & xml) with any TextEditor (Tested with DefaultTextEditor, CompilationUnitEditor, WTP XMl Editor, Android XML Editor)
4. Hold CTRL and move mouse into open Editor
5. Boom:
java.lang.ClassCastException: test.HyperlinkDetectorTest cannot be cast to org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector
	at org.eclipse.ui.texteditor.HyperlinkDetectorDescriptor$1.run(HyperlinkDetectorDescriptor.java:102)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.ui.texteditor.HyperlinkDetectorDescriptor.createHyperlinkDetector(HyperlinkDetectorDescriptor.java:114)
	at org.eclipse.ui.texteditor.HyperlinkDetectorRegistry$HyperlinkDetectorDelegate.detectHyperlinks(HyperlinkDetectorRegistry.java:72)
	at org.eclipse.jface.text.hyperlink.HyperlinkManager.findHyperlinks(HyperlinkManager.java:286)
	at org.eclipse.jface.text.hyperlink.HyperlinkManager.findHyperlinks(HyperlinkManager.java:258)
	at org.eclipse.jface.text.hyperlink.HyperlinkManager.mouseMove(HyperlinkManager.java:462)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:212)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1029)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:923)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Comment 4 Thomas Neumeier CLA 2013-05-01 16:16:21 EDT
HyperlinkDetectorDescriptor is from org.eclipse.ui.workbench.texteditor (3.8.0.v20120523-1310) "Text Editor Framework" [Active]
Comment 5 Thomas Neumeier CLA 2013-05-01 16:22:31 EDT
(In reply to comment #2)
> > CustomHyperlinkDetector
> 
> There is no such class in the Eclipse SDK.
> 
> See also
> http://www.eclipse.org/eclipse/platform-text/development/bug-incomplete.htm

The name was meant as a placeholder for a user contributed class implementing IHyperlinkDetector. In the attached Testproject it is named HyperlinkDetectorTest
Comment 6 Nitin Dahyabhai CLA 2013-05-01 17:20:03 EDT
I think the point is that the extension point documentation for Juno SR2, which reads "the fully qualified class name implementing the interface org.eclipse.jface.text.hyperlink.IHyperlinkDetector. Subclass org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector if you want to access context that is provided by the target", makes it sound like subclassing AbstractHyperlinkDetector is optional. WTP has at least one detector that does not.
Comment 7 Dani Megert CLA 2013-05-02 03:18:38 EDT
(In reply to comment #6)
> WTP has at least one detector that does not.

But wouldn't it then run into the ClassCastException? And wouldn't you have seen this immediately when testing it?


Note that the code and the extension point doc are like that since 3.3 (2007).
Comment 8 Dani Megert CLA 2013-05-02 03:20:41 EDT
Created attachment 230385 [details]
Fix
Comment 9 Nitin Dahyabhai CLA 2013-05-02 10:47:37 EDT
(In reply to comment #7)
> (In reply to comment #6)
> > WTP has at least one detector that does not.
> 
> But wouldn't it then run into the ClassCastException? And wouldn't you have
> seen this immediately when testing it?

Apparently the class was copied in at the project's inception in 2007 but never declared/contributed as an extension.  I only found it by using the type hierarchy.