Skip to content

Uncovered catch blocks #959

@CaelmBleidd

Description

@CaelmBleidd

Description

UTBot doesn't take into account information about coverage of catch blocks. Therefore, in some cases it might lose branches that cover several abstract paths with the same start and end, but they are different because of the catch blocks in the middle of the paths.

To Reproduce

Steps to reproduce the behaviour:

  1. Run UTBot java samples project
  2. Run generation for
  3. Open the generated test org.utbot.examples.exceptions.ExceptionExamples#nestedCatch
  4. Check resulting coverage

Expected behaviour

Three branches with results 1000, 1110, 1100

Actual behaviour

Only two branches are found.

Visual proofs
image

public int nestedCatch(int i, int j) {
    int r = 0;

    try {
        checkPositive(i);
    } catch (NullPointerException e) {
        try {
            checkPositive(j);
        } catch (NullPointerException ex) {
            r += 10;
        } finally {
            r += 100;
        }
    } finally {
        r += 1000;
    }

    return r;
}

Environment

There is no specific environment.

Additional context

Probably, the reason is that UTBot tries to cover catch block only after an exception has already been thrown. But if we have a situation where throwing this exception is an instruction we have already covered, we will drop the one leading to the catch block.

Metadata

Metadata

Assignees

Labels

comp-symbolic-engineIssue is related to the symbolic execution enginectg-bugIssue is a bug

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions