I am fetching some data from a remote service using Spring's RestTemplate:
ResponseEntity<....> result = restTemplate.exchange(....);
...and then I am using result for further processing, and hence I am invoking various methods on it, like:
result.getHeaders().getContentType().getType()
result.getBody()
result.getHeaders().getContentType().getSubtype()
Sonar doesn't like this code and reports 'Possible null pointer dereference' error on almost all of these method calls. It seems I need to have null check on almost every return value.
This makes my code with too many null checks.
Can this be avoided?