为什么使用DatatypeConverter的静态方法的NPE? [英] Why the NPE using static method of DatatypeConverter?

查看:676
本文介绍了为什么使用DatatypeConverter的静态方法的NPE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这短短的code过长呆住了,不能为我的生活中看到它如何可以抛出一个 NullPointerException异常第6行为什么NPE ?

I have stared at this short code too long, and cannot for the life of me see how it can throw a NullPointerException on line 6. Why the NPE?

class ConvertTest {

    public static void main(String[] args) throws Exception {
        byte[] b = "Ha".getBytes("UTF-8");
        System.out.println("bytes: " + b.length);
        javax.xml.bind.DatatypeConverter.printBase64Binary(b);  // NPE!
    }
}

输出

bytes: 2
Exception in thread "main" java.lang.NullPointerException
        at javax.xml.bind.DatatypeConverter.printBase64Binary(DatatypeConverter.java:547)
        at ConvertTest.main(ConvertTest.java:6)
Press any key to continue . . .

更新

虽然很多的bug报告都指向一个变种1.7,我感到很惊讶地看到,Eclipse的配置为使用 1.6.0_32 &安培; TextPad发现了一个版本 1.6.0-B105的(甚至没有意识到安装!)。

Update

While many of the bug reports are pointing to a 1.7 variant, I was astonished to see that Eclipse is configured to use 1.6.0_32 & TextPad has found a version of 1.6.0-b105 (didn't even realize that was installed!).

两者的JRE失败,并NPE。

Both JREs fail with that NPE.

推荐答案

这好像有内JDK7的bug JAXB现在,作为骆驼证明了这个问题:

It seems as though there are bugs in JAXB within JDK7 right now, as evidenced by this issue on Camel:

https://issues.apache.org/jira/browse/CAMEL-4893

860 在java.net上的JAXB项目。

which ultimately links to this issue http://java.net/jira/browse/JAXB-860 in the JAXB project on java.net.

我不能完全肯定,如果你正在运行到同样的事情或没有,但也许尝试使用JDK6了最新版本的JAXB那里,看看是否相同NPE发生或没有。

I'm not entirely sure if you are running into this same thing or not, but perhaps try using JDK6 with the latest JAXB version there and see if the same NPE happens or not.

这篇关于为什么使用DatatypeConverter的静态方法的NPE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆