Alex Rivera | Logout

Findbugs gives "Null pointer dereference of System.out", why?

Asked 2011-07-06T16:07:25.417
18

I am using Java 1.7, Eclipse 3.7 with the FindBugs plugin from the marketplace. The example is as nice as heaven:

class Application
{
  public static void main( String[] args )
  {
    System.out.println( "Bla" );
  }
}

This message was not present in the past and the internal implementation was always in System:

public final static PrintStream out = null;

So Findbugs IS right, but did something change that the message occur now?

Edit
Report

1 Answer

15

Because in java 6 it looked like this:

public final static PrintStream out = nullPrintStream();

/**
 * The following two methods exist because in, out, and err must be
 * initialized to null.  The compiler, however, cannot be permitted to
 * inline access to them, since they are later set to more sensible values
 * by initializeSystemClass().
 */
private static PrintStream nullPrintStream() throws NullPointerException {
    if (currentTimeMillis() > 0) {
        return null;
    }
    throw new NullPointerException();
}

so I guess they simplified it in java 7 and added some exceptions to the compiler.

JVM manages out, in, and err in native code, so this error message it gives is pointless.

answered 2011-07-06T16:58:51.227

Your Answer