SonarQubeCommunity / sonar-pdf-report

81 stars 81 forks source link

Fix NullPointerException - return w/ no resources #4

Closed justinharringa closed 10 years ago

justinharringa commented 10 years ago

There are some cases when a call to the API will return a response body with no resources. In this case, the Measures class will fail with a NullPointerException because it expects to be able to fetch both //resources/resource/date and //resources/resource/version.

This commit adds null checks for these and adds some tests for the following methods (spelling was corrected on addMeasureFromNode(Node):

justinharringa commented 10 years ago

Note that the behavior I saw was similar to this: http://www.marshut.com/irxkpz/nullpointerexception-with-pdf-report-1-3-2-and-sonar-3-7-4.html

After turning on debugging on this legacy project I noticed that this failed after an API call which resulted in XML with only a parent "resources" element:

00:12:29.175 [DEBUG] HTTP Request: http://mysonarserver.com:8080/sonar/api/resources?resource=com.groupid:artifactid&depth=0&format=xml&includetrends=true&metrics=it_branch_coverage

amuniz commented 10 years ago

Hi Justin,

I'll review your PR as soon as possible.

Thanks for the contribution.