Skip to content

Engine doesn't cover branch with "not instanceof" #820

Open
@sergeypospelov

Description

@sergeypospelov

Description

Engine generates 7 executions for this method, but doesn't cover "else" branch for condition (cs1 instanceof String && cs2 instanceof String).

public static boolean equals(CharSequence cs1, CharSequence cs2) {
    if (cs1 == cs2) {
        return true;
    } else if (cs1 != null && cs2 != null) {
        if (cs1.length() != cs2.length()) {
            return false;
        } else if (cs1 instanceof String && cs2 instanceof String) {
            return cs1.equals(cs2);
        } else {
            // Engine never comes into this branch
            int length = cs1.length();
             
            for(int i = 0; i < length; ++i) {
                if (cs1.charAt(i) != cs2.charAt(i)) {
                    return false;
                }
            }
             
            return true;
         }
     } else {
        return false;
    }
}

It happens because of wrappers: we create an object with the only type and concrete implementation. Therefore we don't have any type to !instanceof branch. So we have to work with them both with concrete implementation and without. When we face instanceof instruction, we should use concrete in true branch, otherwise use pure symbolic version

To Reproduce

Steps to reproduce the behavior:

  1. Create the mentioned method
  2. Use plugin to generate tests
  3. Open the generated test
  4. Run tests with coverage

Expected behavior

All branches are covered.

Actual behavior

There is uncovered branch.

Visual proofs (screenshots, logs, images)

image

Metadata

Metadata

Assignees

Labels

comp-symbolic-engineIssue is related to the symbolic execution enginectg-bugIssue is a bugspec-release-tailingsFailed to include in the current release, let's include it in the next one

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions