Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in FlutterTestReportParser when trying to run sonar-scanner #13

Closed
hemmesdev opened this issue May 6, 2020 · 1 comment
Labels
bug Something isn't working fixed on develop

Comments

@hemmesdev
Copy link

hemmesdev commented May 6, 2020

Hi, i got a problem running sonar scanner with flutter plugin. I'm getting a NullPointerException in the FlutterTestReportParser

15:32:43.766 ERROR: Error during SonarQube Scanner execution
java.lang.NullPointerException
	at fr.insideapp.sonarqube.flutter.tests.FlutterTestReportParser.parse(FlutterTestReportParser.java:58)
	at fr.insideapp.sonarqube.flutter.tests.FlutterTestReportParser.parse(FlutterTestReportParser.java:42)
	at fr.insideapp.sonarqube.flutter.tests.FlutterTestSensor.execute(FlutterTestSensor.java:57)

The problem is cause by an empty line in the tests.output.

flutter test --machine > tests.output

The output that i am getting has an empty line at the end of the file.

{"protocolVersion":"0.1.1","runnerVersion":null,"pid":18104,"type":"start","time":0}
{"suite":{"id":0,"platform":"vm","path":"D:\\Development\\ASD\\Project\\mobile_applicatie_submarine\\test\\widget_test.dart"},"type":"suite","time":0}
{"test":{"id":1,"name":"loading D:\\Development\\ASD\\Project\\mobile_applicatie_submarine\\test\\widget_test.dart","suiteID":0,"groupIDs":[],"metadata":{"skip":false,"skipReason":null},"line":null,"column":null,"url":null},"type":"testStart","time":2}
{"count":1,"type":"allSuites","time":4}
{"testID":1,"result":"success","skipped":false,"hidden":true,"type":"testDone","time":2820}
{"group":{"id":2,"suiteID":0,"parentID":null,"name":null,"metadata":{"skip":false,"skipReason":null},"testCount":1,"line":null,"column":null,"url":null},"type":"group","time":2826}
{"test":{"id":3,"name":"Counter increments smoke test","suiteID":0,"groupIDs":[2],"metadata":{"skip":false,"skipReason":null},"line":123,"column":5,"url":"package:flutter_test/src/widget_tester.dart","root_line":14,"root_column":3,"root_url":"file:///D:/Development/ASD/Project/mobile_applicatie_submarine/test/widget_test.dart"},"type":"testStart","time":2830}
{"testID":3,"result":"success","skipped":false,"hidden":false,"type":"testDone","time":3624}
{"success":true,"type":"done","time":3667}

When it gets parsed in the FlutterTestReportParser.parse method on line 46 it throws a NullPointerException because:

String[] lines = input.split(System.getProperty("line.separator")); // also returns the empty lines
for (int i = 0; i < lines.length; i++) {
    String line = lines[i];
    JSONObject obj = (JSONObject)JSONValue.parse(line); // is null if its an empty line

    // Suites
    if (obj.containsKey("suite")) { // if obj is null this wil result in a NullPointerException

Could you please add a null check on the "JSONObject obj" in the FlutterTestReportParser.parse?

@zippy1978
Copy link
Contributor

Hi,
This issue was fixed in 0.3.0.
I close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed on develop
Projects
None yet
2 participants