OpenJDK JAXB实现中的奇怪NullPointerException Catch [英] Strange NullPointerException Catch in OpenJDK JAXB Implementation
问题描述
我在OpenJDK JAXB中发现了一些奇怪的代码:
I found some strange code in OpenJDK JAXB:
com.sun.xml.internal.bind.v2.model.impl.ModelBuilder
com.sun.xml.internal.bind.v2.model.impl.ModelBuilder
try {
XmlSchema s = null;
s.location();
} catch (NullPointerException e) {
// as expected
} catch (NoSuchMethodError e) {
...
}
有人可以解释他们这样做的原因吗?或者这只是一个需要修复的错误代码。
Can some explain why they do this? Or this is just a bad code need to fix.
推荐答案
他们使用此代码作为测试来确定哪个版本的 JAXB(JSR-222) 正在使用API 。如果 NoSuchMethodError $ c,
location
参数已添加到JAXB 2.1中的 @XmlSchema
抛出$ c>然后使用JAXB 2.0 API。
They are using this code as a test to determine which version of the JAXB (JSR-222) APIs are being used. The location
parameter was added to @XmlSchema
in JAXB 2.1, if NoSuchMethodError
was thrown then JAXB 2.0 APIs are being used.
参见第158-177行
- http://grepcode.com/file/repo1.maven.org/maven2/org.jvnet.jaxb.reflection/jaxb2-reflection/2.1.4/org/jvnet/jaxb/reflection/model/impl/ModelBuilder.java
Javadoc - @XmlSchema.location
- http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/annotation/XmlSchema.html#location()
这篇关于OpenJDK JAXB实现中的奇怪NullPointerException Catch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!