开发者

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 m开发者_如何学编程essage 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?


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜