Findbugs 给出“System.out 的空指针取消引用”,为什么?

发布于 2024-11-19 00:46:51 字数 339 浏览 3 评论 0 原文

我正在使用 Java 1.7、Eclipse 3.7 以及市场上的 FindBugs 插件。这个例子就像天堂一样好:

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

这个消息在过去不存在,内部实现总是在系统中:

public final static PrintStream out = null;

所以Findbugs是正确的,但是现在出现这个消息有什么变化吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

森林很绿却致人迷途 2024-11-26 00:46:51

因为在java 6中它看起来像这样:

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();
}

所以我猜他们在java 7中简化了它并向编译器添加了一些异常。

JVM 管理本机代码中的 out、in 和 err,因此它给出的错误消息是毫无意义的。

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.

扛刀软妹 2024-11-26 00:46:51

这被标记为错误 在 Findbugs 1.3.9 中。它已针对 Findbugs 2.0 进行修复,并且可能会向后移植。

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

傲性难收 2024-11-26 00:46:51

只有openjdk才会出现这种情况,sun jdk不会出现这种情况。

该问题是 2010 年发布的一个补丁,允许系统时间早于 1970 年。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文