8/3/2011

I Just Found Java Compiler Bug

Filed under: — Aviran Mordo

I just found a bug in Java compiler (java version “1.6.0_24″), where the compiler allows to return null in a method signature that return int.

Here is an example of the code that should not compile.


public int foo()
{
return true ? null : 0;
}

Of course the “true” can be replaced with any boolean expression.

The java compiler compiles this code without problem, however at runtime you’ll get NullPointerException.

Powered by WordPress