Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeSet tests contain too much reflection with system classes #1282

Open
alisevych opened this issue Nov 1, 2022 · 2 comments
Open

TreeSet tests contain too much reflection with system classes #1282

alisevych opened this issue Nov 1, 2022 · 2 comments
Assignees
Labels
comp-symbolic-engine Issue is related to the symbolic execution engine ctg-bug Issue is a bug

Comments

@alisevych
Copy link
Member

alisevych commented Nov 1, 2022

Description

Symbolic execution for examples using TreeSet produces tests with too complex reflection with system classes.

To Reproduce

  1. Install the latest UnitTestBot plugin build from main in IntelliJ Idea 2022.2.3 (latest)
  2. Create a Gradle project with JDK 11
  3. Add a Java class with the following method:
    /**
     * Should create TreeSet without any modifications as T extends Number is not Comparable
     */
    public <T extends Number> boolean testTreeSetWithoutComparable(NavigableSet<T> set) {
        if (set.size() > 5) {
            return true;
        }
        return false;
    }

    /**
     * Should create TreeSet with modifications as Integer is Comparable
     */
    public boolean testTreeSetWithComparable(NavigableSet<Integer> set) {
        if (set.size() > 5) {
            return true;
        }
        return false;
    }
  1. Generate tests with Symbolic execution only (100%) and Mock everything outside package

Expected behavior

Generated tests are supposed to instantiate objects regularly.

Actual behavior

Generated tests contain too much reflection with system classes

Visual proofs (screenshots, logs, images)

    ///region Test suites for executable org.utbot.examples.collections.CollectionExample.testTreeSetWithComparable

    ///region

    @Test
    public void testTestTreeSetWithComparable1() {
        CollectionExample collectionExample = new CollectionExample();
        
        /* This test fails because method [org.utbot.examples.collections.CollectionExample.testTreeSetWithComparable] produces [java.lang.NullPointerException]
            org.utbot.examples.collections.CollectionExample.testTreeSetWithComparable(CollectionExample.java:124) */
        collectionExample.testTreeSetWithComparable(null);
    }

    @Test
    public void testTestTreeSetWithComparable2() throws Exception {
        CollectionExample collectionExample = new CollectionExample();
        ConcurrentSkipListSet set = ((ConcurrentSkipListSet) createInstance("java.util.concurrent.ConcurrentSkipListSet"));
        ConcurrentSkipListMap concurrentSkipListMap = ((ConcurrentSkipListMap) createInstance("java.util.concurrent.ConcurrentSkipListMap"));
        Object index = createInstance("java.util.concurrent.ConcurrentSkipListMap$Index");
        Object node = createInstance("java.util.concurrent.ConcurrentSkipListMap$Node");
        setField(index, "java.util.concurrent.ConcurrentSkipListMap$Index", "node", node);
        setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "head", index);
        LongAdder longAdder = ((LongAdder) createInstance("java.util.concurrent.atomic.LongAdder"));
        Object[] cellArray = createArray("java.util.concurrent.atomic.Striped64$Cell", 32);
        setField(longAdder, "java.util.concurrent.atomic.Striped64", "cells", cellArray);
        setField(longAdder, "java.util.concurrent.atomic.Striped64", "base", 0L);
        setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "adder", longAdder);
        setField(set, "java.util.concurrent.ConcurrentSkipListSet", "m", concurrentSkipListMap);

        boolean actual = collectionExample.testTreeSetWithComparable(set);

        assertFalse(actual);

        ConcurrentNavigableMap setM = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setMMAdder = ((LongAdder) getFieldValue(setM, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setMMAdderMAdderCells = getFieldValue(setMMAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells0 = get(setMMAdderMAdderCells, 0);
        ConcurrentNavigableMap setM1 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM1MAdder = ((LongAdder) getFieldValue(setM1, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM1MAdderMAdderCells = getFieldValue(setM1MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells1 = get(setM1MAdderMAdderCells, 1);
        ConcurrentNavigableMap setM2 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM2MAdder = ((LongAdder) getFieldValue(setM2, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM2MAdderMAdderCells = getFieldValue(setM2MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells2 = get(setM2MAdderMAdderCells, 2);
        ConcurrentNavigableMap setM3 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM3MAdder = ((LongAdder) getFieldValue(setM3, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM3MAdderMAdderCells = getFieldValue(setM3MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells3 = get(setM3MAdderMAdderCells, 3);
        ConcurrentNavigableMap setM4 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM4MAdder = ((LongAdder) getFieldValue(setM4, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM4MAdderMAdderCells = getFieldValue(setM4MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells4 = get(setM4MAdderMAdderCells, 4);
        ConcurrentNavigableMap setM5 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM5MAdder = ((LongAdder) getFieldValue(setM5, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM5MAdderMAdderCells = getFieldValue(setM5MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells5 = get(setM5MAdderMAdderCells, 5);
        ConcurrentNavigableMap setM6 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM6MAdder = ((LongAdder) getFieldValue(setM6, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM6MAdderMAdderCells = getFieldValue(setM6MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells6 = get(setM6MAdderMAdderCells, 6);
        ConcurrentNavigableMap setM7 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM7MAdder = ((LongAdder) getFieldValue(setM7, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM7MAdderMAdderCells = getFieldValue(setM7MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells7 = get(setM7MAdderMAdderCells, 7);
        ConcurrentNavigableMap setM8 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM8MAdder = ((LongAdder) getFieldValue(setM8, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM8MAdderMAdderCells = getFieldValue(setM8MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells8 = get(setM8MAdderMAdderCells, 8);
        ConcurrentNavigableMap setM9 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM9MAdder = ((LongAdder) getFieldValue(setM9, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM9MAdderMAdderCells = getFieldValue(setM9MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells9 = get(setM9MAdderMAdderCells, 9);
        ConcurrentNavigableMap setM10 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM10MAdder = ((LongAdder) getFieldValue(setM10, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM10MAdderMAdderCells = getFieldValue(setM10MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells10 = get(setM10MAdderMAdderCells, 10);
        ConcurrentNavigableMap setM11 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM11MAdder = ((LongAdder) getFieldValue(setM11, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM11MAdderMAdderCells = getFieldValue(setM11MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells11 = get(setM11MAdderMAdderCells, 11);
        ConcurrentNavigableMap setM12 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM12MAdder = ((LongAdder) getFieldValue(setM12, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM12MAdderMAdderCells = getFieldValue(setM12MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells12 = get(setM12MAdderMAdderCells, 12);
        ConcurrentNavigableMap setM13 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM13MAdder = ((LongAdder) getFieldValue(setM13, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM13MAdderMAdderCells = getFieldValue(setM13MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells13 = get(setM13MAdderMAdderCells, 13);
        ConcurrentNavigableMap setM14 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM14MAdder = ((LongAdder) getFieldValue(setM14, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM14MAdderMAdderCells = getFieldValue(setM14MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells14 = get(setM14MAdderMAdderCells, 14);
        ConcurrentNavigableMap setM15 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM15MAdder = ((LongAdder) getFieldValue(setM15, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM15MAdderMAdderCells = getFieldValue(setM15MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells15 = get(setM15MAdderMAdderCells, 15);
        ConcurrentNavigableMap setM16 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM16MAdder = ((LongAdder) getFieldValue(setM16, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM16MAdderMAdderCells = getFieldValue(setM16MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells16 = get(setM16MAdderMAdderCells, 16);
        ConcurrentNavigableMap setM17 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM17MAdder = ((LongAdder) getFieldValue(setM17, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM17MAdderMAdderCells = getFieldValue(setM17MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells17 = get(setM17MAdderMAdderCells, 17);
        ConcurrentNavigableMap setM18 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM18MAdder = ((LongAdder) getFieldValue(setM18, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM18MAdderMAdderCells = getFieldValue(setM18MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells18 = get(setM18MAdderMAdderCells, 18);
        ConcurrentNavigableMap setM19 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM19MAdder = ((LongAdder) getFieldValue(setM19, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM19MAdderMAdderCells = getFieldValue(setM19MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells19 = get(setM19MAdderMAdderCells, 19);
        ConcurrentNavigableMap setM20 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM20MAdder = ((LongAdder) getFieldValue(setM20, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM20MAdderMAdderCells = getFieldValue(setM20MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells20 = get(setM20MAdderMAdderCells, 20);
        ConcurrentNavigableMap setM21 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM21MAdder = ((LongAdder) getFieldValue(setM21, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM21MAdderMAdderCells = getFieldValue(setM21MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells21 = get(setM21MAdderMAdderCells, 21);
        ConcurrentNavigableMap setM22 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM22MAdder = ((LongAdder) getFieldValue(setM22, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM22MAdderMAdderCells = getFieldValue(setM22MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells22 = get(setM22MAdderMAdderCells, 22);
        ConcurrentNavigableMap setM23 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM23MAdder = ((LongAdder) getFieldValue(setM23, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM23MAdderMAdderCells = getFieldValue(setM23MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells23 = get(setM23MAdderMAdderCells, 23);
        ConcurrentNavigableMap setM24 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM24MAdder = ((LongAdder) getFieldValue(setM24, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM24MAdderMAdderCells = getFieldValue(setM24MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells24 = get(setM24MAdderMAdderCells, 24);
        ConcurrentNavigableMap setM25 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM25MAdder = ((LongAdder) getFieldValue(setM25, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM25MAdderMAdderCells = getFieldValue(setM25MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells25 = get(setM25MAdderMAdderCells, 25);
        ConcurrentNavigableMap setM26 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM26MAdder = ((LongAdder) getFieldValue(setM26, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM26MAdderMAdderCells = getFieldValue(setM26MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells26 = get(setM26MAdderMAdderCells, 26);
        ConcurrentNavigableMap setM27 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM27MAdder = ((LongAdder) getFieldValue(setM27, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM27MAdderMAdderCells = getFieldValue(setM27MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells27 = get(setM27MAdderMAdderCells, 27);
        ConcurrentNavigableMap setM28 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM28MAdder = ((LongAdder) getFieldValue(setM28, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM28MAdderMAdderCells = getFieldValue(setM28MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells28 = get(setM28MAdderMAdderCells, 28);
        ConcurrentNavigableMap setM29 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM29MAdder = ((LongAdder) getFieldValue(setM29, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM29MAdderMAdderCells = getFieldValue(setM29MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells29 = get(setM29MAdderMAdderCells, 29);
        ConcurrentNavigableMap setM30 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM30MAdder = ((LongAdder) getFieldValue(setM30, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM30MAdderMAdderCells = getFieldValue(setM30MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells30 = get(setM30MAdderMAdderCells, 30);
        ConcurrentNavigableMap setM31 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM31MAdder = ((LongAdder) getFieldValue(setM31, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM31MAdderMAdderCells = getFieldValue(setM31MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells31 = get(setM31MAdderMAdderCells, 31);

        assertNull(finalSetMAdderCells0);

        assertNull(finalSetMAdderCells1);

        assertNull(finalSetMAdderCells2);

        assertNull(finalSetMAdderCells3);

        assertNull(finalSetMAdderCells4);

        assertNull(finalSetMAdderCells5);

        assertNull(finalSetMAdderCells6);

        assertNull(finalSetMAdderCells7);

        assertNull(finalSetMAdderCells8);

        assertNull(finalSetMAdderCells9);

        assertNull(finalSetMAdderCells10);

        assertNull(finalSetMAdderCells11);

        assertNull(finalSetMAdderCells12);

        assertNull(finalSetMAdderCells13);

        assertNull(finalSetMAdderCells14);

        assertNull(finalSetMAdderCells15);

        assertNull(finalSetMAdderCells16);

        assertNull(finalSetMAdderCells17);

        assertNull(finalSetMAdderCells18);

        assertNull(finalSetMAdderCells19);

        assertNull(finalSetMAdderCells20);

        assertNull(finalSetMAdderCells21);

        assertNull(finalSetMAdderCells22);

        assertNull(finalSetMAdderCells23);

        assertNull(finalSetMAdderCells24);

        assertNull(finalSetMAdderCells25);

        assertNull(finalSetMAdderCells26);

        assertNull(finalSetMAdderCells27);

        assertNull(finalSetMAdderCells28);

        assertNull(finalSetMAdderCells29);

        assertNull(finalSetMAdderCells30);

        assertNull(finalSetMAdderCells31);
    }
    ///endregion

    ///endregion

    ///region Test suites for executable org.utbot.examples.collections.CollectionExample.testTreeSetWithoutComparable

    ///region

    @Test
    public void testTestTreeSetWithoutComparable1() {
        CollectionExample collectionExample = new CollectionExample();
        
        /* This test fails because method [org.utbot.examples.collections.CollectionExample.testTreeSetWithoutComparable] produces [java.lang.NullPointerException]
            org.utbot.examples.collections.CollectionExample.testTreeSetWithoutComparable(CollectionExample.java:114) */
        collectionExample.testTreeSetWithoutComparable(null);
    }

    @Test
    public void testTestTreeSetWithoutComparable2() throws Exception {
        CollectionExample collectionExample = new CollectionExample();
        ConcurrentSkipListSet set = ((ConcurrentSkipListSet) createInstance("java.util.concurrent.ConcurrentSkipListSet"));
        ConcurrentSkipListMap concurrentSkipListMap = ((ConcurrentSkipListMap) createInstance("java.util.concurrent.ConcurrentSkipListMap"));
        Object index = createInstance("java.util.concurrent.ConcurrentSkipListMap$Index");
        Object node = createInstance("java.util.concurrent.ConcurrentSkipListMap$Node");
        setField(index, "java.util.concurrent.ConcurrentSkipListMap$Index", "node", node);
        setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "head", index);
        LongAdder longAdder = ((LongAdder) createInstance("java.util.concurrent.atomic.LongAdder"));
        Object[] cellArray = createArray("java.util.concurrent.atomic.Striped64$Cell", 2);
        setField(longAdder, "java.util.concurrent.atomic.Striped64", "cells", cellArray);
        setField(longAdder, "java.util.concurrent.atomic.Striped64", "base", 0L);
        setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "adder", longAdder);
        setField(set, "java.util.concurrent.ConcurrentSkipListSet", "m", concurrentSkipListMap);

        boolean actual = collectionExample.testTreeSetWithoutComparable(set);

        assertFalse(actual);

        ConcurrentNavigableMap setM = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setMMAdder = ((LongAdder) getFieldValue(setM, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setMMAdderMAdderCells = getFieldValue(setMMAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells0 = get(setMMAdderMAdderCells, 0);
        ConcurrentNavigableMap setM1 = ((ConcurrentNavigableMap) getFieldValue(set, "java.util.concurrent.ConcurrentSkipListSet", "m"));
        LongAdder setM1MAdder = ((LongAdder) getFieldValue(setM1, "java.util.concurrent.ConcurrentSkipListMap", "adder"));
        Object setM1MAdderMAdderCells = getFieldValue(setM1MAdder, "java.util.concurrent.atomic.Striped64", "cells");
        Object finalSetMAdderCells1 = get(setM1MAdderMAdderCells, 1);

        assertNull(finalSetMAdderCells0);

        assertNull(finalSetMAdderCells1);
    }
    ///endregion

    ///endregion

Environment

Windows 10 Pro
IntelliJ IDEA 2022.1.4 (JBR 11)
UTBotJava project (Gradle , JDK 11)

Additional context

Code taken from PR - #988

@alisevych alisevych added ctg-bug Issue is a bug comp-symbolic-engine Issue is related to the symbolic execution engine labels Nov 1, 2022
@korifey korifey moved this to Todo in UTBot Java Nov 1, 2022
@alisevych
Copy link
Member Author

Additional context

Without changes from PR - #1265 - the reflection in test class is a bit different. But too much reflection is also present.
Following tests are generated with this build
With same settings - Symbolic execution only (100%) and Mock everything outside package

    ///region Test suites for executable org.utbot.examples.collections.CollectionExample.testTreeSetWithComparable

    ///region

    @Test
    public void testTestTreeSetWithComparable1() {
        CollectionExample collectionExample = new CollectionExample();
        
        /* This test fails because method [org.utbot.examples.collections.CollectionExample.testTreeSetWithComparable] produces [java.lang.NullPointerException]
            org.utbot.examples.collections.CollectionExample.testTreeSetWithComparable(CollectionExample.java:124) */
        collectionExample.testTreeSetWithComparable(null);
    }

    @Test
    public void testTestTreeSetWithComparable2() throws Exception {
        CollectionExample collectionExample = new CollectionExample();
        ConcurrentSkipListSet set = ((ConcurrentSkipListSet) createInstance("java.util.concurrent.ConcurrentSkipListSet"));
        ConcurrentSkipListMap concurrentSkipListMap = ((ConcurrentSkipListMap) createInstance("java.util.concurrent.ConcurrentSkipListMap"));
        setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "head", null);
        setField(set, "java.util.concurrent.ConcurrentSkipListSet", "m", concurrentSkipListMap);

        boolean actual = collectionExample.testTreeSetWithComparable(set);

        assertFalse(actual);
    }

    @Test
    public void testTestTreeSetWithComparable3() throws Exception {
        CollectionExample collectionExample = new CollectionExample();
        ConcurrentSkipListSet set = ((ConcurrentSkipListSet) createInstance("java.util.concurrent.ConcurrentSkipListSet"));
        ConcurrentSkipListMap concurrentSkipListMap = ((ConcurrentSkipListMap) createInstance("java.util.concurrent.ConcurrentSkipListMap"));
        Object index = createInstance("java.util.concurrent.ConcurrentSkipListMap$Index");
        Object node = createInstance("java.util.concurrent.ConcurrentSkipListMap$Node");
        setField(index, "java.util.concurrent.ConcurrentSkipListMap$Index", "node", node);
        setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "head", index);
        LongAdder longAdder = ((LongAdder) createInstance("java.util.concurrent.atomic.LongAdder"));
        Object[] cellArray = createArray("java.util.concurrent.atomic.Striped64$Cell", 0);
        setField(longAdder, "java.util.concurrent.atomic.Striped64", "cells", cellArray);
        setField(longAdder, "java.util.concurrent.atomic.Striped64", "base", 2147483647L);
        setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "adder", longAdder);
        setField(set, "java.util.concurrent.ConcurrentSkipListSet", "m", concurrentSkipListMap);

        boolean actual = collectionExample.testTreeSetWithComparable(set);

        assertTrue(actual);
    }
    ///endregion

    ///endregion

    ///region Test suites for executable org.utbot.examples.collections.CollectionExample.testTreeSetWithoutComparable

    ///region

    @Test
    public void testTestTreeSetWithoutComparable1() {
        CollectionExample collectionExample = new CollectionExample();
        
        /* This test fails because method [org.utbot.examples.collections.CollectionExample.testTreeSetWithoutComparable] produces [java.lang.NullPointerException]
            org.utbot.examples.collections.CollectionExample.testTreeSetWithoutComparable(CollectionExample.java:114) */
        collectionExample.testTreeSetWithoutComparable(null);
    }

    @Test
    public void testTestTreeSetWithoutComparable2() throws Exception {
        CollectionExample collectionExample = new CollectionExample();
        ConcurrentSkipListSet set = ((ConcurrentSkipListSet) createInstance("java.util.concurrent.ConcurrentSkipListSet"));
        ConcurrentSkipListMap concurrentSkipListMap = ((ConcurrentSkipListMap) createInstance("java.util.concurrent.ConcurrentSkipListMap"));
        setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "head", null);
        setField(set, "java.util.concurrent.ConcurrentSkipListSet", "m", concurrentSkipListMap);

        boolean actual = collectionExample.testTreeSetWithoutComparable(set);

        assertFalse(actual);
    }

    @Test
    public void testTestTreeSetWithoutComparable3() throws Exception {
        CollectionExample collectionExample = new CollectionExample();
        ConcurrentSkipListSet set = ((ConcurrentSkipListSet) createInstance("java.util.concurrent.ConcurrentSkipListSet"));
        ConcurrentSkipListMap concurrentSkipListMap = ((ConcurrentSkipListMap) createInstance("java.util.concurrent.ConcurrentSkipListMap"));
        Object index = createInstance("java.util.concurrent.ConcurrentSkipListMap$Index");
        Object node = createInstance("java.util.concurrent.ConcurrentSkipListMap$Node");
        setField(index, "java.util.concurrent.ConcurrentSkipListMap$Index", "node", node);
        setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "head", index);
        LongAdder longAdder = ((LongAdder) createInstance("java.util.concurrent.atomic.LongAdder"));
        Object[] cellArray = createArray("java.util.concurrent.atomic.Striped64$Cell", 0);
        setField(longAdder, "java.util.concurrent.atomic.Striped64", "cells", cellArray);
        setField(longAdder, "java.util.concurrent.atomic.Striped64", "base", 2147483647L);
        setField(concurrentSkipListMap, "java.util.concurrent.ConcurrentSkipListMap", "adder", longAdder);
        setField(set, "java.util.concurrent.ConcurrentSkipListSet", "m", concurrentSkipListMap);

        boolean actual = collectionExample.testTreeSetWithoutComparable(set);

        assertTrue(actual);
    }
    ///endregion

    ///endregion

@CaelmBleidd
Copy link
Member

The reason for it -- we don't have a wrapper for TreeSet, NavigableSet and OrderedSet, and the right way to fix it -- create such wrappers. It is definitely a problem, but I think we are unable to fix it before the nearest release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-symbolic-engine Issue is related to the symbolic execution engine ctg-bug Issue is a bug
Projects
Status: Todo
Development

No branches or pull requests

2 participants