question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullPointerException in com.github.tomakehurst.wiremock.matching.EqualToJsonPattern.getNode during record

See original GitHub issue

The`ret.get(keyInt) in the row return getNode(ret.get(keyInt), path, ++pos); will under certain conditions be null because keyInt is larger than the size of ret.

How to reproduce: Add the two following classes directly on the same level as com.github.tomakehurst.wiremock.WireMockServer and add compile “commons-io:commons-io:2.4” compile ‘io.rest-assured:rest-assured:3.0.3’ to build.gradle.

package com.github.tomakehurst.wiremock;

import com.github.tomakehurst.wiremock.common.SingleRootFileSource; import org.apache.commons.io.FileUtils;

import java.io.File;

import static com.github.tomakehurst.wiremock.client.WireMock.*; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;

public class Buggtest {

public static String URL = "/post";
public static String PROXYBASEURL = "http://httpbin.org";


public static void main(String[] args) {
    new Buggtest().tst();
}
void tst() {
    WireMockServer wireMockServer=null;
    try {
        wireMockServer = new WireMockServer(options().port(8099));
        wireMockServer.start();
        FileUtils.cleanDirectory(new File("/tmp/mappings"));
        FileUtils.cleanDirectory(new File("/tmp/__files"));
        wireMockServer.enableRecordMappings(new SingleRootFileSource("/tmp/mappings"), new SingleRootFileSource("/tmp/__files"));
        configureFor("localhost", 8099);
        stubFor(post(urlEqualTo(URL)).willReturn(aResponse().proxiedFrom(PROXYBASEURL)));
        Caller c = new Caller();
        c.call();
        wireMockServer.stop();
    }
    catch (Exception e){
        e.printStackTrace();
    }
    finally {
        if (wireMockServer!=null && wireMockServer.isRunning()) {
            wireMockServer.stop();
        }
    }
}

}


package com.github.tomakehurst.wiremock;

import com.jayway.jsonpath.JsonPath; import io.restassured.RestAssured; import io.restassured.response.Response;

import static io.restassured.RestAssured.given;

public class Caller { void call() {

    String[] request=new String[2];
    request[0] = "{\"columns\": [{\"name\": \"x\",\"y\": 3},{\"name\": \"agreementnumber\",\"a\": 1},{\"name\": \"agreementstatus\",\"b\": 2}]}";
    request[1] = "{\"columns\": [{\"name\": \"agreementnumber\",\"a\": 1},{\"name\": \"utilizerstatus\",\"b\": 2}]}";


    //for(int i=request.length-1;i>=0;i--) {
    for(int i=0;i<request.length;i++) {
        System.out.println("Doing request: " + request[i]);
        Response r = given().contentType("application/json").body(request[i]).when().post("http://localhost:8099"+ Buggtest.URL);
        String body = r.getBody().asString();
        System.out.println("Request response:\n------8<----------------------------" );
        System.out.println(body);
        System.out.println("--------------------------------------->8-------");

    }
}

public static void main(String[] args) {
    Caller c = new Caller();
    c.call();
}

}


The second call will result in: Error 500 Problem accessing /post. Reason: java.lang.NullPointerException

The error do not happen if you change the order of the calls (reverse the for-loop in class Caller) or if you change columns to columnsZ the second request string.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
foikilacommented, Aug 3, 2017

@tomakehurst Had any time yet? 😃

0reactions
tomakehurstcommented, Oct 19, 2017

Has anyone checked whether this is an issue with the new record feature?

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullPointerException in com.github.tomakehurst.wiremock ...
NullPointerException in com.github.tomakehurst.wiremock.matching.EqualToJsonPattern.getNode during record #691.
Read more >
A brand new website interface for an even better experience!
NullPointerException in com.github.tomakehurst.wiremock.matching.EqualToJsonPattern.getNode during record.
Read more >
Is WireMock thread safe? - Google Groups
NullPointerException. at com.github.tomakehurst.wiremock.matching.EqualToJsonPattern.getNode(EqualToJsonPattern.java:148).
Read more >
How to use EqualToJsonPattern in com.github.tomakehurst ...
Best Java code snippets using com.github.tomakehurst.wiremock.matching.EqualToJsonPattern (Showing top 12 results out of 315) · WireMock.equalToJson(...).
Read more >
JsonMappingException when trying to transform a ...
But When I do this, a NPE is thrown when the Json conversion is ... Json.write(Json.java:74) at com.github.tomakehurst.wiremock.recording.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found