Home

Jump statements should not be followed by dead code

Rule description

  • Jump statements should not be followed by dead code

 

Non-compliant Code Example

BEGIN
	FOR i IN 1 .. CUSTOMER_TABLE.COUNT  
		LOOP	
			EXIT WHEN CUSTOMER_TABLE(i).Id > 25;        --Non compliant code (Dead code after exit statement)
			IF CUSTOMER_TABLE(i) IS NOT NULL THEN
				DBMS_OUTPUT.PUT( i || ' = (' || CUSTOMER_TABLE(i).Name || ', ' || CUSTOMER_TABLE(i).PhoneNumber || ')' );
			END IF;
			
		END LOOP;
EXCEPTION
  WHEN ERRORS THEN
	RETURN;
END CUSTOMER_TABLE_ITERATION;
function GetCompleteCustomerDetails(FirstName in nvarchar2,
LastName in nvarchar2,
ADDRESS1 in nvarchar2,
ADDRESS2 in nvarchar2,
Area in nvarchar2,
City in nvarchar2)return nvarchar2    --Compliant code 
IS
BEGIN
	RETURN(CONCAT(CONCAT(CONCAT(FirstName,LastName),CONCAT(ADDRESS1,ADDRESS2)),CONCAT(Area,City))); 
	
	CONCAT(CONCAT(ADDRESS1,ADDRESS2),CONCAT(Area,City));        --Non compliant code (Dead code after return statement)
	
END GetCompleteCustomerDetails;

Compliant Code Example

BEGIN
	FOR i IN 1 .. CUSTOMER_TABLE.COUNT  
		LOOP	
			IF CUSTOMER_TABLE(i) IS NOT NULL THEN
				DBMS_OUTPUT.PUT( i || ' = (' || CUSTOMER_TABLE(i).Name || ', ' || CUSTOMER_TABLE(i).PhoneNumber || ')' );
			END IF;
			EXIT WHEN CUSTOMER_TABLE(i).Id > 25;        --Compliant code (No dead code after exit statement)
		END LOOP;
EXCEPTION
  WHEN ERRORS THEN
	RETURN;
END CUSTOMER_TABLE_ITERATION;
function GetCompleteCustomerDetails(FirstName in nvarchar2,
LastName in nvarchar2,
ADDRESS1 in nvarchar2,
ADDRESS2 in nvarchar2,
Area in nvarchar2,
City in nvarchar2)return nvarchar2    --Compliant code 
IS
BEGIN
    CONCAT(CONCAT(ADDRESS1,ADDRESS2),CONCAT(Area,City));        --Compliant code (No dead code after return statement)	
    RETURN(CONCAT(CONCAT(CONCAT(FirstName,LastName),CONCAT(ADDRESS1,ADDRESS2)),CONCAT(Area,City))); 
END GetCompleteCustomerDetails;
Visual Expert 2020
 VEPLSQLRULE61