title: "java.lang.NullPointerException: Cannot invoke method startsWith() on null object" in RestAssured
body: <p>I am writing the below code for a test program in RestAssured with Maven and TestNG but getting NullPointerException. It is working well till the status(200) check. The issue is with the body assertion.</p>
  <pre><code>import static io.restassured.RestAssured.*;
  import static org.hamcrest.Matchers.*;
  import org.testng.annotations.Test;
  
  public class Test01_GET {
  
      String baseEndPoint = &quot;https://reqres.in/api/users?page=2&quot;;
  
      @Test
      public void test_03_get() {
  
          given()
                  .get(baseEndPoint)
                  .then()
                  .statusCode(200)
                  .assertThat()
                  .body(&quot;page&quot;, equalTo(2));
      }
      
  }
  </code></pre>
  <p>The end point returns the below JSON document.</p>
  <pre><code>{
    &quot;page&quot;: 2,
    &quot;per_page&quot;: 6,
    &quot;total&quot;: 12,
    &quot;total_pages&quot;: 2,
    &quot;data&quot;: [
      {
        &quot;id&quot;: 7,
        &quot;email&quot;: &quot;michael.lawson@reqres.in&quot;,
        &quot;first_name&quot;: &quot;Michael&quot;,
        &quot;last_name&quot;: &quot;Lawson&quot;,
        &quot;avatar&quot;: &quot;https://s3.amazonaws.com/uifaces/faces/twitter/follettkyle/128.jpg&quot;
      },
      {
        &quot;id&quot;: 8,
        &quot;email&quot;: &quot;lindsay.ferguson@reqres.in&quot;,
        &quot;first_name&quot;: &quot;Lindsay&quot;,
        &quot;last_name&quot;: &quot;Ferguson&quot;,
        &quot;avatar&quot;: &quot;https://s3.amazonaws.com/uifaces/faces/twitter/araa3185/128.jpg&quot;
      },
      {
        &quot;id&quot;: 9,
        &quot;email&quot;: &quot;tobias.funke@reqres.in&quot;,
        &quot;first_name&quot;: &quot;Tobias&quot;,
        &quot;last_name&quot;: &quot;Funke&quot;,
        &quot;avatar&quot;: &quot;https://s3.amazonaws.com/uifaces/faces/twitter/vivekprvr/128.jpg&quot;
      }
  }
  </code></pre>
  <p>I have added the necessary dependencies in pom.xml file.</p>
  <pre><code>&lt;dependencies&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;io.rest-assured&lt;/groupId&gt;
              &lt;artifactId&gt;rest-assured&lt;/artifactId&gt;
              &lt;version&gt;4.3.0&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.testng&lt;/groupId&gt;
              &lt;artifactId&gt;testng&lt;/artifactId&gt;
              &lt;version&gt;7.1.0&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hamcrest&lt;/groupId&gt;
              &lt;artifactId&gt;hamcrest-all&lt;/artifactId&gt;
              &lt;version&gt;1.3&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  </code></pre>
  <p>But I am getting the below exception. Cannot solve it in anyway. Please help.</p>
  <pre><code>java.lang.NullPointerException: Cannot invoke method startsWith() on null object
  
      at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:44)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:34)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
      at io.restassured.internal.path.json.JSONAssertion.getAsJsonObject(JSONAssertion.groovy:53)
      at io.restassured.internal.path.json.JSONAssertion$getAsJsonObject.callCurrent(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:185)
      at io.restassured.internal.path.json.JSONAssertion.getResult(JSONAssertion.groovy:28)
      at io.restassured.internal.common.assertion.Assertion$getResult.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:148)
      at io.restassured.assertion.BodyMatcher.validate(BodyMatcher.groovy:94)
      at io.restassured.assertion.BodyMatcher$validate$0.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:157)
      at io.restassured.assertion.BodyMatcherGroup$_validate_closure2.doCall(BodyMatcherGroup.groovy:47)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
      at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:263)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1029)
      at groovy.lang.Closure.call(Closure.java:412)
      at groovy.lang.Closure.call(Closure.java:428)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:3564)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:3549)
      at org.codehaus.groovy.runtime.DefaultGroovyMethods.collect(DefaultGroovyMethods.java:3649)
      at org.codehaus.groovy.runtime.dgm$101.invoke(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:247)
      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
      at io.restassured.assertion.BodyMatcherGroup.validate(BodyMatcherGroup.groovy:47)
      at io.restassured.assertion.BodyMatcherGroup$validate$3.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:157)
      at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure.validate(ResponseSpecificationImpl.groovy:480)
      at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure$validate$1.call(Unknown Source)
      at io.restassured.internal.ResponseSpecificationImpl.validateResponseIfRequired(ResponseSpecificationImpl.groovy:674)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:193)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:61)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:185)
      at io.restassured.internal.ResponseSpecificationImpl.body(ResponseSpecificationImpl.groovy:261)
      at io.restassured.specification.ResponseSpecification$body$1.callCurrent(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:212)
      at io.restassured.internal.ResponseSpecificationImpl.body(ResponseSpecificationImpl.groovy:108)
      at io.restassured.internal.ValidatableResponseOptionsImpl.body(ValidatableResponseOptionsImpl.java:244)
      at io.restassured.internal.ValidatableResponseImpl.super$2$body(ValidatableResponseImpl.groovy)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1262)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:144)
      at io.restassured.internal.ValidatableResponseImpl.body(ValidatableResponseImpl.groovy:298)
      at io.restassured.internal.ValidatableResponseImpl.body(ValidatableResponseImpl.groovy)
      at Test01_GET.test_03_get(Test01_GET.java:45)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:134)
      at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:597)
      at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
      at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
      at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:816)
      at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
      at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
      at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
      at org.testng.TestRunner$$Lambda$49/0000000000000000.accept(Unknown Source)
      at java.util.ArrayList.forEach(ArrayList.java:1257)
      at org.testng.TestRunner.privateRun(TestRunner.java:766)
      at org.testng.TestRunner.run(TestRunner.java:587)
      at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
      at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
      at org.testng.SuiteRunner.run(SuiteRunner.java:286)
      at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
      at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
      at org.testng.TestNG.runSuitesSequentially(TestNG.java:1187)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:1109)
      at org.testng.TestNG.runSuites(TestNG.java:1039)
      at org.testng.TestNG.run(TestNG.java:1007)
      at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
      at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:110)
  
  
  ===============================================
  Default Suite
  Total tests run: 1, Passes: 0, Failures: 1, Skips: 0
  ===============================================
  
  
  Process finished with exit code 0
  </code></pre>