GWT and method overriding

162 views
Skip to first unread message

gktcs

unread,
Jan 31, 2012, 12:30:47 AM1/31/12
to google-we...@googlegroups.com
I was hoping someone could explain to me why the following isn't working in GWT.  I've been staring at this for a while now and clearly I'm missing something simple.  Hopefully someone can hit me with a clue stick and fill me in on what I'm missing.

We have a custom callback class defined as:
public abstract class MyCallback<T> implements AsyncCallback<T>

which looks at the exception type in onFailure and takes some action based on the class type.  A new type check has been added:
public void onFailure(Throwable t) {
  ...
  if (t instanceof SomeException) {
    handleException((SomeException)t);
  }

where handleException(SomeException) is defined in the custom callback class as:
public void handleException(SomeException ex) {
   // empty
}

When the callback object is actually created and used in an RPC dispatch (we're using gwt-dispatch), the handleException method is defined then:
dispatch.execute(someAction, new MyCallback<someActionResult>() {
   // implementation of a couple abstract methods from MyCallback

  public void handleException(SomeException ex) {
    // do actual work here
  }
});

The issue is that the "do actual work" handleException method is never being called.  Only the base handleException (the empty one in MyCallback) is being called, not the overridden method.  I'm sure I've completely overlooked something simple so any explanation as to why it's not/won't work, or how to get it working would be greatly appreciated.  It seems like something similar works in Java, just curious how to get it working here.

Thank you in advance.


l3dx

unread,
Jan 31, 2012, 1:25:18 AM1/31/12
to google-we...@googlegroups.com
Add the @Override annotation to be 100% sure that you're actually overriding the handleException in the abstract class. (Then you will get a compiler error if not).

/l3dx

gktcs

unread,
Jan 31, 2012, 9:18:31 AM1/31/12
to google-we...@googlegroups.com
The override has been there all along (I was hoping it wasn't), I just forgot to put it in my sample code.  The callback instance is defined as:

dispatch.execute(someAction, new MyCallback<someActionResult>() {
   // implementation of a couple abstract methods from MyCallback

  @Override
  public void handleException(SomeException ex) {
    // do actual work here
  }
});

Not sure if it matters, but the callback code above is behind an application split point.  
We're using GWT 2.4.0.

gktcs

unread,
Jan 31, 2012, 12:48:22 PM1/31/12
to google-we...@googlegroups.com
Ugh.  Never mind, user error.  Functionality works as expected.  I forgot we had an additional layer wrapping the original callback; updated that and everything works as expected.
Reply all
Reply to author
Forward
0 new messages