Status code should be checked instead of parsing the error message to maintain the backward compatibility.
1public void branchingNoncompliant() {
2 AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
3 try {
4 s3Client.doesObjectExist("bucketName", "key");
5 } catch (AmazonServiceException e) {
6 // Noncompliant: checks the status message of the exception instead of the status code.
7 if (e.getMessage().contains("bucketName")) {
8 log.info("one thing");
9 } else {
10 log.info("another thinking");
11 }
12 }
13}