«« Thinking About the Sweet Spot Playlist Support Back In »»
blog header image
SWT AssertionFailedException

If you're getting this error in your SWT program:

org.eclipse.core.internal.runtime.AssertionFailedException: assertion failed: The application has not been initialized.

then code that SWT is calling is throwing an exception that is not being caught, probably a runtime exception like NullPointerException. SWT seems to catch all exceptions and then throw this generic one.

Why throw this cryptic general error message with no hint as to the real problem? I don't know but it's really not that helpful for debugging the problem. There's probably a good reason for it though because it's not an ideal solution. Ha, does that make sense? :)

To find out what's wrong you can wrap calls to methods outside of SWT in try/catch blocks. Normally I wouldn't advocate catching Exception but in this situation wrapping it in a try/catch block temporarily is a good way to figure out what's wrong. Usually I do something like:

try
{
   applicationCode.someMethod(value);
}
catch (Exception e)
{
   System.out.println("exception thrown by call to someMethod(): " + e);
   e.printStackTrace();
}

This will print a full stack trace in the Eclipse console view. Then after you debug the problem take the try/catch block out. It's not going to do much good to you in production when users can't see the command line, a console view (stdout).

So I guess this is where the log file solution comes in that I talked about earler. You could catch all exceptions (even runtime) coming from outside SWT and log the exceptions with stack traces to a file. This is what Eclipse does if I'm not mistaken -- at least it did in 2002 when I worked at Rational.

I wonder if you could use aspectj to do something like "every time I call outside of SWT wrap it in a try/catch block 'automatically' and log the exceptions to a file." Then you wouldn't have to clutter up your code with explicit try/catch blocks and better yet you wouldn't have to remember to try/catch every time. That kind of thing would be much less error prone. Unfortunately I don't know enough about aspectj to know if this is possible. Time to find out I think...

Posted at February 22, 2004 at 06:40 AM EST
Last updated February 22, 2004 at 06:40 AM EST
Comments

What was the ultimate bug in your case?

» Posted by: aforward at February 22, 2004 11:51 AM

All sorts of bugs. I get AssertionFailedException every once in a while when I get lazy, especially when I forget to properly check parameters before I send them to methods. ClassCastException and NullPointerException are the usual the culprits.

I use collections a lot, so when I refactor sometimes I get ClassCastExceptions: put one class of object into a collection and take it out and cast it to another incorrectly. I can't wait for generics -- it will make refactoring collections a lot easier.

» Posted by: Ryan at February 22, 2004 12:25 PM
Google
 
Search scope: Web ryanlowe.ca