Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 938
Johnannes Münch Avatar asked Jul 06 '11 16:07

Johnannes Münch


3 Answers

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.

like image 139
Denis Tulskiy Avatar answered Oct 06 '22 01:10

Denis Tulskiy


This is marked as a bug in Findbugs 1.3.9. It has been fixed for Findbugs 2.0, and might be backported.

like image 38
Thirler Avatar answered Oct 05 '22 23:10

Thirler


This only happens with openjdk, not the sun jdk.

The problem is a patch posted in 2010 to allow system times older than 1970.

http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2010-July/009869.html

like image 41
Ivan Kelly Avatar answered Oct 05 '22 23:10

Ivan Kelly