Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » PageBookView.getAdapter produces StackOverflowError
PageBookView.getAdapter produces StackOverflowError [message #535805] Tue, 25 May 2010 13:32
Eric Jain is currently offline Eric Jain
Messages: 266
Registered: July 2009
Senior Member
org.eclipse.ui.part.PageBookView's implementation of getAdapter checks if the current Page is an instance of the required class and returns it if true.

So I registered the following handler and adapter factory:

<handler class="TestHandler" commandId="test">
  <activeWhen>
    <with variable="activePartId">
      <equals value="testView"/>
    </with>
  </activeWhen>
  <enabledWhen>
    <with variable="activePart">
      <adapt type="Navigable">
        <test property="navigable" value="true"/>
      </adapt>
    </with>
  </enabledWhen>
</handler>
...
<extension point="org.eclipse.core.runtime.adapters">
  <factory 
    adaptableType="TestView"
    class="AdaptableAdapterFactory"
  >
    <adapter type="Navigable"/>
  </factory>
</extension>


TestView is a PageBookView, and AdaptableAdapterFactory simply casts the TestView to an IAdaptable and calls getAdapter on it (used elsewhere and works fine). The Pages in the PageBookView implement the Navigable interface.

Now this is what I get whenever the enablement logic is triggered:

!ENTRY org.eclipse.osgi 4 0 2010-05-24 13:50:22.484
!MESSAGE Application error
!STACK 1
java.lang.StackOverflowError
	at java.util.HashMap.get(HashMap.java:300)
	at java.util.Collections$SynchronizedMap.get(Collections.java:1975)
	at org.eclipse.core.internal.runtime.AdapterManager.getFactories(AdapterManager.java:205)
	at org.eclipse.core.internal.runtime.AdapterManager.getAdapter(AdapterManager.java:290)
	at org.eclipse.ui.internal.util.Util.getAdapter(Util.java:119)
	at org.eclipse.ui.part.PageBookView.getAdapter(PageBookView.java:578)
	at AdaptableAdapterFactory.getAdapter(AdaptableAdapterFactory.java:14)
	at org.eclipse.core.internal.adapter.AdapterFactoryProxy.getAdapter(AdapterFactoryProxy.java:80)
	at org.eclipse.core.internal.runtime.AdapterManager.getAdapter(AdapterManager.java:293)
	at org.eclipse.ui.part.WorkbenchPart.getAdapter(WorkbenchPart.java:151)
	at org.eclipse.ui.part.PageBookView.getAdapter(PageBookView.java:589)
	at AdaptableAdapterFactory.getAdapter(AdaptableAdapterFactory.java:14)
	at org.eclipse.core.internal.adapter.AdapterFactoryProxy.getAdapter(AdapterFactoryProxy.java:80)
	at org.eclipse.core.internal.runtime.AdapterManager.getAdapter(AdapterManager.java:293)
	at org.eclipse.ui.part.WorkbenchPart.getAdapter(WorkbenchPart.java:151)
	at org.eclipse.ui.part.PageBookView.getAdapter(PageBookView.java:589)
	...


If I override getAdapter in TestView like so all works fine:

public Object getAdapter(Class key) {
    if (Navigable.class.equals(key)) {
        if (getCurrentPage() instanceof Navigable) {
            return getCurrentPage();
        }
    }
    return null;
}


This is a simple workaround, but I'm still curious why I can't delegate to the super class, and whom to blame for that...

[Updated on: Tue, 25 May 2010 13:33]

Report message to a moderator

Previous Topic:Handle Import Event
Next Topic:PropertyTester on list of objects
Goto Forum:
  


Current Time: Thu Apr 24 01:52:17 EDT 2014

Powered by FUDForum. Page generated in 0.02999 seconds