Mutually exclusive call High

Calls to mutually exclusive methods were found in the code. This could indicate a bug or a deeper problem.

Detector ID
java/mutually-exclusive-calls-found@v1.0
Category
Common Weakness Enumeration (CWE) external icon
-

Noncompliant example

1public void ec2RunInstancesNoncompliant(String templateName, String templateID, String zone) {
2    AmazonEC2 ec2Client = AmazonEC2ClientBuilder.standard().withRegion(Regions.US_WEST_2).build();
3    // Noncompliant: uses mutually exclusive withLaunchTemplateId and withLaunchTemplateName together.
4    RunInstancesResult runInstancesResult = ec2Client.runInstances(
5            new RunInstancesRequest()
6                    .withPlacement(new Placement().withAvailabilityZone(zone))
7                    .withInstanceType(InstanceType.T2Micro)
8                    .withInstanceInitiatedShutdownBehavior("terminate")
9                    .withMinCount(1)
10                    .withMaxCount(2)
11                    .withLaunchTemplate(
12                            new LaunchTemplateSpecification()
13                                    .withLaunchTemplateName(templateName)
14                                    .withLaunchTemplateId(templateID)
15                    )
16    );
17}

Compliant example

1public void ec2RunInstancesCompliant(String templateName, String templateID, String zone) {
2    AmazonEC2 ec2Client = AmazonEC2ClientBuilder.standard().withRegion(Regions.US_WEST_2).build();
3    // Compliant: uses only withLaunchTemplateId.
4    RunInstancesResult runInstancesResult = ec2Client.runInstances(
5            new RunInstancesRequest()
6                    .withPlacement(new Placement().withAvailabilityZone(zone))
7                    .withInstanceType(InstanceType.T2Micro)
8                    .withInstanceInitiatedShutdownBehavior("terminate")
9                    .withMinCount(1)
10                    .withMaxCount(2)
11                    .withLaunchTemplate(
12                            new LaunchTemplateSpecification()
13                                    .withLaunchTemplateId(templateID)
14                    )
15    );
16}