Search code examples
javanullpointerexceptionlejos-nxj

Is it standard behavior for this code to throw a NullPointerException?


I've had a big problem in some library code, which I've pinned down to a single statement:

System.out.println((String) null);

Ok, the code doesn't actually look like that, but it certainly calls println with a null argument. Doing this causes my whole applicaio to throw an unexpected NullPointerException.

In general, should println throw this exception under that circumstance, or is this non-standard behavior due to a poor implementation of the out instance?


Solution

  • The JVM of sun prints simply "null". This is the specified behavior of PrintStream.print(String) when given a null argument.