If a method that uses an input parameter to update an output value throws an exception, then the output value is not updated. When this happens, the method's input and output values become out of sync.
1void outOfSyncNoncompliant(String deploymentId) {
2 String deploymentItem = null;
3 try {
4 // Noncompliant: the output value would not be updated if the producing method
5 // throws an exception, resulting the input and output values becoming out of sync.
6 deploymentItem = loadDeployment(deploymentId);
7 } catch (final Exception e) {
8 log.warn("Exception: ", e);
9 }
10 doSomething(deploymentId, deploymentItem);
11}
1void outOfSyncCompliant(String deploymentId) {
2 String deploymentItem = null;
3 try {
4 deploymentItem = loadDeployment(deploymentId);
5 } catch (final Exception e) {
6 log.warn("Exception: ", e);
7 deploymentId=null;
8 }
9 // Compliant: the input value is reset, resulting the input and output values to stay in sync.
10 doSomething(deploymentId, deploymentItem);
11}