Lets say I invoke AWS APIs in my java/kotlin code. Example on getHostedZone route53 API below.
- Should I check if response == null first or is response guaranteed to be non null? Is null pointer check handling needed A or B?
A:
val request = GetHostedZoneRequest.builder().id(hostedZoneId).build()
val response = route53Client.getHostedZone(request)
if (response.hostedZone().config().privateZone() == false) {
// my private zone handling logic
}
(or) B:
val request = GetHostedZoneRequest.builder().id(hostedZoneId).build()
val response = route53Client.getHostedZone(request)
if(response != null) {
if (response.hostedZone()?.config()?.privateZone() == false) {
// my private zone handling logic
}
}
- Similarly, I am assuming that hostedZone and config can be null based on the model documentation - GetHostedZoneResponse and HostedZone and checking
hostedZone()?.config()?.privateZone()is the right way. Is this assumption correct ?
Because I find my IDE not warning about these null checks, I am wondering if these checks are an overkill or not. Under the hood, are these null checks done as expected during an API call.
- Can I expect valid exceptions to be thrown in case of timeouts or other failures from AWS and not check for null (I understand there are known exceptions that can be handled for aws api calls respectively.) ? This question applies to most of the aws service api calls I believe and I couldn't find a satisfactory answer or best practice from the documentation.