Tag Archives: java

Static Initialization in the BlackBerry JVM

The Problem

I was investigating some odd behavior on the BlackBerry recently to try to diagnose a problem. Along the way, I discovered a bug in BlackBerry’s JVM, as a result of which static initialization can occur multiple times – and even static final variables can change.

Consider the following code:

public class App extends Application
{
	public static void main(String[] args)
	{
		System.out.println(BaseClass.class.getName());
		System.out.println(Subclass.class.getName());
	}
}

public class BaseClass
{
	static
	{
		System.out.println("Static initialization called");
	}
}

public class Subclass extends BaseClass
{

}

Continue reading Static Initialization in the BlackBerry JVM

Blackberry Swallowed My Error

In some peculiar cases there will be an error thrown somewhere in the Blackberry modules that were invoked from your coed, but the error will never return to you, even with a try-catch block set. The stack trace of the error will be printed to the console, your process will be terminated and an error message will pop up on the device/simulator screen with: Uncaught exception: and the exception name.

An example for this is the Controlled Access Exception. When trying to open a file that is access controlled, even a specific catch for this error it will not matter, the process will be killed and the error window for uncaught exception will pop up. The best practice is of course to check for access control before reaching for the file, but it still doesn’t make sense to have it swallow the error and kill the process instead of bubbling it up. Also, for the access control it’s pretty straight forward, but now I have encountered it again, with a java.lang.Error exception and the process gets killed… java.lang.Error is slightly less informative than ControlledAccess Continue reading Blackberry Swallowed My Error