NPE: "Cannot invoke method getType() on null object" after a put()

487 views
Skip to first unread message

Ted M. Young

unread,
Jul 18, 2013, 8:41:57 PM7/18/13
to rest-a...@googlegroups.com
For one particular test, we're getting an NPE from the REST-assured package. The stacktrace is below. The test is as follows:

  @Test
  public void responseStatusCodeIs200AndUserIsUpdatedWhenETagsMatch() throws Exception {
    Response response =
        given()
        .contentType(MediaType.APPLICATION_FORM_URLENCODED)
        .formParam("first", "First")
        .formParam("last", "Last")
        .formParam("username", "fname")
    .when()
        .put("/ab:1");

    String eTag = eTagFrom(response);

    given()
        .header("If-Match", eTag)
        .contentType(MediaType.APPLICATION_FORM_URLENCODED)
        .formParam("first", "First")
        .formParam("last", "L.")
        .formParam("username", "fl")
    .expect()
        .statusCode(200)
        .body("first", equalTo("First"))
        .body("last", equalTo("L."))
        .body("username", equalTo("fl"))
    .when()
        .put("/ab:1");
  }

The service is returning a 412 (because of a bug in the app code), but this test fails with an NPE instead of an incorrect expectation.

Any ideas?


java.lang.NullPointerException: Cannot invoke method getType() on null object
                at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
                at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
                at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
                at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32)
                at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
                at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
                at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
                at com.jayway.restassured.internal.path.json.ConfigurableJsonSlurper.parse(ConfigurableJsonSlurper.groovy:93)
                at com.jayway.restassured.internal.path.json.ConfigurableJsonSlurper$parse.call(Unknown Source)
                at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
                at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
                at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
                at com.jayway.restassured.internal.ContentParser.parse(ContentParser.groovy:36)
                at com.jayway.restassured.internal.ContentParser$parse.call(Unknown Source)
                at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
                at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
                at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
                at com.jayway.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure.validate(ResponseSpecificationImpl.groovy:389)
                at com.jayway.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure$validate.call(Unknown Source)
                at com.jayway.restassured.internal.RequestSpecificationImpl.invokeFilterChain(RequestSpecificationImpl.groovy:759)
                at com.jayway.restassured.internal.RequestSpecificationImpl$invokeFilterChain.callCurrent(Unknown Source)
                at com.jayway.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1142)
                at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy)
                at com.jayway.restassured.internal.RequestSpecificationImpl$this$2$applyPathParamsAndSendRequest.callCurrent(Unknown Source)
                at com.jayway.restassured.internal.RequestSpecificationImpl.put(RequestSpecificationImpl.groovy:139)
                at com.jayway.restassured.specification.RequestSender$put.call(Unknown Source)
                at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
                at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
                at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
                at com.jayway.restassured.internal.ResponseSpecificationImpl.put(ResponseSpecificationImpl.groovy:234)
                at com.guidewire.activitymanager.UserResourceIntegrationTest.responseStatusCodeIs200AndUserIsUpdatedWhenETagsMatch(UserResourceIntegrationTest.java:389)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
                at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
                at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
                at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
                at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
                at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
                at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
                at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
                at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
                at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
                at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
                at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
                at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
                at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
                at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
                at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
                at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
                at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
                at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
                at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)


Johan Haleby

unread,
Jul 19, 2013, 1:11:31 AM7/19/13
to rest-a...@googlegroups.com
What version of REST Assured are you using? If you're not using the latest one please upgrade and see if you still experience the same problems.

Regards,
/Johan


--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ted M. Young [@jitterted]

unread,
Jul 19, 2013, 1:38:09 PM7/19/13
to rest-a...@googlegroups.com
We're using 1.8.1. Not sure if it matters, but we had to exclude the Groovy from REST-Assured and depend on 2.1.2 separately, e.g.:

    <dependency>
      <groupId>com.jayway.restassured</groupId>
      <artifactId>rest-assured</artifactId>
      <version>1.8.1</version>
      <exclusions>
        <!-- Exclude Groovy because of classpath issue -->
        <exclusion>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy</artifactId>
        </exclusion>
      </exclusions>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <!-- Needs to be the same version that REST Assured depends on -->
      <version>2.1.2</version>
      <scope>test</scope>
    </dependency>

;ted



--
You received this message because you are subscribed to a topic in the Google Groups "REST assured" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rest-assured/6iy6rVJP00g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rest-assured...@googlegroups.com.

Johan Haleby

unread,
Nov 24, 2013, 5:16:44 AM11/24/13
to rest-a...@googlegroups.com
Sorry for the veeery late response but could you please tell me how the response looks like? Preferably with all headers etc as well.

/Johan
Reply all
Reply to author
Forward
0 new messages