David Chandler's Journal of Java Web and Mobile Development

  • David M. Chandler

    Web app developer since 1994 and Google Cloud Platform Instructor now residing in Colorado. Besides tech, I enjoy landscape photography and share my work at ColoradoPhoto.gallery.

  • Subscribe

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 224 other followers
  • Sleepless Nights…

    December 2009
    S M T W T F S
  • Blog Stats

    • 1,035,335 hits

GWT-RPC exception handling gotcha

Posted by David Chandler on December 4, 2009

A few weeks ago, I posted some GWT-RPC serialization gotchas. At first, this looks like a GWT-RPC serialization problem:

SEVERE: [1259963134337000] javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: Type 'javax.jdo.JDOFatalUserException' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.

Hmmm, GWT-RPC is probably trying to serialize JDOFatalUserException because one is being thrown somewhere. But why don’t I see it in my logs? I’m catching all RuntimeExceptions in my RemoteServiceServlet and logging a warning with the message.

On closer inspection, I found the warning message just prior to the stack trace; however, it was not clearly associated with JDOFatalUserException because I had used e.getMessage() instead of e.toString().

In the process, however, I discovered that GWT-RPC masks many exceptions. Here is the code in GWT’s RPC.class that actually executes your service method via reflection:

    try {
      Object result = serviceMethod.invoke(target, args);

      responsePayload = encodeResponseForSuccess(serviceMethod, result,
    } catch (IllegalAccessException e) {
      SecurityException securityException = new SecurityException(
          formatIllegalAccessErrorMessage(target, serviceMethod));
      throw securityException;
    } catch (IllegalArgumentException e) {
      SecurityException securityException = new SecurityException(
          formatIllegalArgumentErrorMessage(target, serviceMethod, args));
      throw securityException;
    } catch (InvocationTargetException e) {
      // Try to encode the caught exception
      Throwable cause = e.getCause();

      responsePayload = encodeResponseForFailure(serviceMethod, cause,

Note that the catch block for InvocationTargetException attempts to encode (serialize) the root cause exception to send it back to the client. If this fails, however, as in the case of JDOFatalUserException, RPC throws a SerializationException with no information about the root cause!

Moral: make sure your GWT-RPC service methods catch all RuntimeExceptions and log all the info you need. In light of this, I’ve now beefed up my gwt-dispatch service servlet to log a severe message and print a stack trace.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: