Using Jersey Test Framework produces NullPointerException during JerseyTest constructor

I am using Jersey Test Framework, however, even before the code gets to my test, the JerseyTest constructor fails with:

Mar 06, 2014 6:40:44 PM org.glassfish.jersey.server.ApplicationHandler initialize
INFO: Initiating Jersey application, version Jersey: 2.6 2014-02-18 21:52:53...

A MultiException has 3 exceptions.  They are:
1. java.lang.NullPointerException
2. java.lang.IllegalStateException: Unable to perform operation: method inject on com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App
3. java.lang.IllegalStateException: Unable to perform operation: create on org.glassfish.jersey.message.internal.MessageBodyFactory
MultiException stack 1 of 3
    at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.setConfiguration(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at org.glassfish.hk2.utilities.reflection.ReflectionHelper.invoke(
    at org.jvnet.hk2.internal.ClazzCreator.methodMe(
    at org.jvnet.hk2.internal.ClazzCreator.create(
    at org.jvnet.hk2.internal.SystemDescriptor.create(
    at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(
    at org.jvnet.hk2.internal.Utilities.createService(

My test is very simple:

public class BidAPITest extends JerseyTest {

    protected Application configure() {
        return new ResourceConfig(BidAPI.class);

    public void testCreate() {
        final BidDocument
            bid =
                        Entity.entity("", MediaType.APPLICATION_JSON_TYPE),


The actual failure occurs while setConfiguration is being invoked in AbstractJAXBProvider. The actual line which fails in the JettyTest constructor is:

public ComponentModelValidator(ServiceLocator locator) {
    validators = Lists.newArrayList();
    validators.add(new ResourceValidator());
    /* -FAILS-> */ validators.add(new RuntimeResourceModelValidator(locator.getService(MessageBodyWorkers.class)));
    validators.add(new ResourceMethodValidator(locator));
    validators.add(new InvocableValidator());

Any ideas before I start ripping apart my application?

Thanks. -AP_


I ran into the same problem using Spring 3.2.6 & Jersey 2.6. I solved it by upgrading Jersey to version 2.9.1.

Also make sure you are using this dependency to make spring 3 & jersey coexist :


Need Your Help

How can I ensure my process never locks another process out of a file?

c++ c windows winapi file-locking

I have a Windows process that runs in the background and periodically backs up files. The backup is done by uploading the file to a server.

Swift location comes back nil

ios swift mapkit

This code was functioning earlier, and now it keeps crashing because the location is coming back as nil. I'm not sure where this error is coming from or how to fix it. From what I can tell, my c...