OpenJDK JAXB实现中奇怪的NullPointerException捕获

OpenJDK JAXB实现中奇怪的NullPointerException捕获,jaxb,nullpointerexception,openjdk,Jaxb,Nullpointerexception,Openjdk,我在OpenJDK JAXB中发现了一些奇怪的代码: com.sun.xml.internal.bind.v2.model.impl.ModelBuilder 试试看{ XmlSchema s=null; s、 位置(); }捕获(NullPointerException e){ //果然 }捕获(无此错误){ ... } 有人能解释他们为什么这样做吗?或者这只是一个需要修复的错误代码。他们正在使用此代码作为测试,以确定正在使用哪个版本的API。在JAXB 2.1中,location参数被添加

我在OpenJDK JAXB中发现了一些奇怪的代码:

com.sun.xml.internal.bind.v2.model.impl.ModelBuilder

试试看{
XmlSchema s=null;
s、 位置();
}捕获(NullPointerException e){
//果然
}捕获(无此错误){
...
}

有人能解释他们为什么这样做吗?或者这只是一个需要修复的错误代码。

他们正在使用此代码作为测试,以确定正在使用哪个版本的API。在JAXB 2.1中,
location
参数被添加到
@XmlSchema
中,如果抛出了
NoSuchMethodError
,则正在使用JAXB 2.0 API

见第158-177行

Javadoc-@XmlSchema.location


我不反对这种方法错误,但为什么有必要生成NPE?为什么不在某个静态XmlSchema实例上调用location方法呢。NPE使调试复杂化。