rules repository

A-0970 Never place branches after an unconditional branch.

Severity Error Check + SQL-based Test Free New

Reason

Branches on the same branch point run in sequence order and the first one whose condition is met ends the processing. A branch without a condition (and without a button) always fires, so every branch with a higher sequence at the same branch point is dead logic that can never run. This usually hides a mistake, such as a forgotten condition or a wrong sequence.

Give the first branch a condition, move it behind the conditional ones, or delete the unreachable branches.

Example

Non-Compliant Example

page 10 (
    // ...
    branch (
        name: Go Home
        execution {
            sequence: 10
        }
        // no condition -> always fires
        // ...
    )

    branch (
        name: Go Home 2
        execution {
            sequence: 20
        }
        // ...
    )
)
Issues
LineColumnMessage
35Branch is unconditional but followed by other branches that can never run.

Compliant Solution - ★★★★★

page 10 (
    // ...
    branch (
        name: Go Home
        execution {
            sequence: 10
        }
        serverSideCondition {
            type: expression
            plsqlExpression: :P10_TARGET = 'HOME'
            // or whenButtonPressed: @save
        }
        // ...
    )

    branch (
        name: Go Home 2
        execution {
            sequence: 20
        }
        // ...
    )
)

Tests

Test SQL query

select aa.workspace || '.' || aa.alias || '.' || b.page_id || '.' || b.branch_name as identifier,
       'Branch ' || b.branch_name || ' on page ' || b.page_id || ' of app ' || aa.alias || ' in '
         || aa.workspace || ' is unconditional but followed by other branches that can never run.' as message
  from apex_application_page_branches b
  join apex_applications aa
    on aa.application_id = b.application_id
       and aa.workspace = b.workspace
 where aa.workspace in (#ApexWorkspaces#)
   and b.condition_type is null
   and b.when_button_pressed is null
   and exists (select 1
                 from apex_application_page_branches b2
                where b2.application_id = b.application_id
                  and b2.page_id = b.page_id
                  and b2.branch_point = b.branch_point
                  and nvl(b2.authorization_scheme_id, 'X') = nvl(b.authorization_scheme_id, 'X')
                  and b2.branch_id != b.branch_id
                  and b2.process_sequence > b.process_sequence)

Test results

IdentifierMessageMigration
WORKSPACE.CUSTOMERS.10.Go HomeBranch Go Home on page 10 of app CUSTOMERS in WORKSPACE is unconditional but followed by other branches that can never run.-

Parameters

Use parameters to customize the rule to your needs.

ParameterDescriptionDefault Value
ApexWorkspacesComma-separated List of APEX workspaces owning APEX applications to check.dblinter, dbl_gui

References