Skip to content

Instantly share code, notes, and snippets.

@dashorst
Created November 28, 2014 15:00
Show Gist options
  • Save dashorst/051a2cc07ad8f25635ea to your computer and use it in GitHub Desktop.
Save dashorst/051a2cc07ad8f25635ea to your computer and use it in GitHub Desktop.
A brilliant piece of code...
package com.sun.xml.bind.v2.model.impl;
...
public class ModelBuilder {
...
static {
try {
XmlSchema s = null;
s.location();
} catch (NullPointerException e) {
// as epxected
} catch (NoSuchMethodError e) {
// this is not a 2.1 API. Where is it being loaded from?
Messages res;
if (SecureLoader.getClassClassLoader(XmlSchema.class) == null) {
res = Messages.INCOMPATIBLE_API_VERSION_MUSTANG;
} else {
res = Messages.INCOMPATIBLE_API_VERSION;
}
throw new LinkageError( res.format(
Which.which(XmlSchema.class),
Which.which(ModelBuilder.class)
));
}
}
}
@dashorst
Copy link
Author

Isn't this why reflection was invented?

@haster
Copy link

haster commented Nov 28, 2014

It makes me both chuckle and cry every time I see that (usually when I turn on NPE breakpoints in eclipse)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment