“Argument 1 cannot be null” with no line number

The stack trace generation in Apex seems to be broken for at least one NullPointerException case.

This test case illustrates the problem:

private class NpeTest {
    private static void f() {
        Decimal dec1 = 0.00;
        Decimal dec2 = null;
        dec1 += dec2;
    static void test() {

The test results in these messages:

System.NullPointerException: Argument 1 cannot be null
External entry point Class.cve.NpeTest.test: line 10, column 1

and the corresponding debug log adds little.

You can infer that the problem is somewhere in the function f. In this case it is then easy to find: dec1 is being incremented by a null dec2 value at line 6.

But in longer functions (and given that the message “Argument 1 cannot be null” doesn’t immediately suggest a problem in an increment operation) the root cause can be much harder to find.

PS Winter ’13 fixes this.


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 )

Google+ photo

You are commenting using your Google+ 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