Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange NullPointerException Catch in OpenJDK JAXB Implementation

I found some strange code in OpenJDK JAXB:

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.

like image 492
xeranic Avatar asked Sep 03 '25 15:09

xeranic


1 Answers

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.

See Lines 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()
like image 69
bdoughan Avatar answered Sep 05 '25 07:09

bdoughan