Skip to content

Support toArray method for Map keySet and entrySet #525

Open
@alisevych

Description

@alisevych

Description

Test generation using symbolic execution fails for methods containing

  • new toArray method for Map keySet (added for Collections in Java 11)
  • new and old toArray methods for Map entrySet

To Reproduce

Steps to reproduce the behavior:

  1. The following line is present in ~/.utbot/settings.properties :
    useFuzzing=false
  2. Open/restart IntelliJ IDEA with UTBot plugin installed
  3. A project is opened
  4. Add the following class:
import java.util.HashMap;
import java.util.Map;

class A {

    public String[] checkNewToArray() {
        Map<String, String> namesMap = new HashMap<>();
        namesMap.put("Joe", "Jane");
        namesMap.put("Bill", "Anna");
        String[] names = namesMap.entrySet().toArray(String[]::new);
        return names;
    }
}
  1. Initiate test generation with UTBot
  2. Same for the following method calls:

String[] names = namesMap.keySet().toArray(String[]::new);

String[] names = namesMap.entrySet().toArray(new String[2]);

Expected behavior

Tests are supposed to be generated.

Actual behavior

Failed to generate unit tests for class A - error popup is displayed
in 2-3 seconds after start

Visual proofs (screenshots, logs, images)

Map entrySet toArray

Environment

Windows 10 Pro
IntelliJ IDEA Ultimate 2022.1.3
JDK 11

Additional context

Working only with old toArray method for keySet:

String[] names = namesMap.keySet().toArray(new String[2]);

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

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions