Skip to content

Improve NoreturnContractCheck#441

Open
jgardn3r wants to merge 7 commits into
masterfrom
no-return-except-block
Open

Improve NoreturnContractCheck#441
jgardn3r wants to merge 7 commits into
masterfrom
no-return-except-block

Conversation

@jgardn3r
Copy link
Copy Markdown
Collaborator

  • Introduce RoutineExit type to control flow graph types
  • Remove ControlFlowGraph::getExitBlock
  • Fix CFG construction of Continue and Break around try finally
  • Ensure RoutineExit block is always id 0
  • Replace AssertJ withFailMessage with as in CFG BlockChecker
  • Add ExceptionalRoutineExit to appropriate ControlFlowGraphs
  • Improve NoreturnContractCheck

jgardn3r added 5 commits May 12, 2026 11:38
This is to facilitate the distinction between routine exits and
exceptional exits from a control flow graph.
This is being removed in favour of the type system and a more generic
approach to block identification. Additionally, there may be more than
one exit block in a CFG.
This fixes a bug that allowed loop control flow statements to be used
inside `try finally` statements with the existance of a loop.
@jgardn3r jgardn3r requested a review from cirras May 12, 2026 01:39
import au.com.integradev.delphi.cfg.api.RoutineExit;
import au.com.integradev.delphi.cfg.api.UnconditionalJump;
import au.com.integradev.delphi.cfg.api.UnknownException;
import au.com.integradev.delphi.cfg.api.*;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use explicit imports (you may need an IDE configuration change.)

import au.com.integradev.delphi.cfg.api.RoutineExit;
import au.com.integradev.delphi.cfg.api.Terminated;
import au.com.integradev.delphi.cfg.api.UnknownException;
import au.com.integradev.delphi.cfg.api.*;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use explicit imports.

import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.*;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use explicit imports.


// Remove the exceptional exit if there are no paths to it
Block exceptionalExitBlock =
ListUtils.reverse(blocks).stream()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the guava Lists.reverse instead? I don't like the idea of using these super specific collection utils from sonarsource analyzer commons (and trust the long-term stability of Guava's API much more.)

import au.com.integradev.delphi.cfg.api.ControlFlowGraph;
import au.com.integradev.delphi.cfg.api.Terminated;
import au.com.integradev.delphi.cfg.api.UnconditionalJump;
import au.com.integradev.delphi.cfg.api.*;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use explicit imports.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous implementation passes all tests if we simply change the implementation of notFinallyOrExit:

private static boolean notFinallyOrExit(Block block) {
  return !(block instanceof Finally || block instanceof ExceptionalRoutineExit);
}

What's the benefit of the full-on implementation rejig?
If there's some case that this handles that the previous implementation fundamentally doesn't, can we add unit tests to demonstrate that?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rejig made more sense to me. After playing with the existing implementation a bit more, I think the change you suggested is sufficient. I will revert it to that.

@jgardn3r jgardn3r force-pushed the no-return-except-block branch from 33df283 to da15b24 Compare May 13, 2026 01:47
@jgardn3r jgardn3r requested a review from cirras May 13, 2026 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants