diff --git a/.github/workflows/build-and-run-tests-from-branch.yml b/.github/workflows/build-and-run-tests-from-branch.yml index 0fd9ef84d4..98032f7d64 100644 --- a/.github/workflows/build-and-run-tests-from-branch.yml +++ b/.github/workflows/build-and-run-tests-from-branch.yml @@ -112,7 +112,7 @@ jobs: # The option forces to execute all jobs even though some of them have failed. fail-fast: false matrix: - project: [utbot-api, utbot-cli, utbot-core, utbot-framework, utbot-framework-api, utbot-fuzzers, utbot-gradle, utbot-instrumentation, utbot-instrumentation-tests, utbot-intellij, utbot-junit-contest, utbot-rd, utbot-sample, utbot-summary, utbot-summary-tests] + project: [utbot-api, utbot-cli, utbot-core, utbot-framework, utbot-framework-test-java11, utbot-framework-api, utbot-fuzzers, utbot-gradle, utbot-instrumentation, utbot-instrumentation-tests, utbot-intellij, utbot-junit-contest, utbot-rd, utbot-sample, utbot-summary, utbot-summary-tests] runs-on: ubuntu-20.04 container: unittestbot/java-env:java11-zulu-jdk-gradle7.4.2-kotlinc1.7.0 steps: diff --git a/settings.gradle b/settings.gradle index 7e7cd525dc..74a0b7d354 100644 --- a/settings.gradle +++ b/settings.gradle @@ -29,5 +29,6 @@ include 'utbot-gradle' include 'utbot-maven' include 'utbot-summary-tests' include 'utbot-framework-test' +include 'utbot-framework-test-java11' include 'utbot-rd' diff --git a/utbot-framework-test-java11/README.md b/utbot-framework-test-java11/README.md new file mode 100644 index 0000000000..7ab2880286 --- /dev/null +++ b/utbot-framework-test-java11/README.md @@ -0,0 +1 @@ +Engine/codegen unit tests that require Java 11 features \ No newline at end of file diff --git a/utbot-framework-test-java11/build.gradle b/utbot-framework-test-java11/build.gradle new file mode 100644 index 0000000000..e2792fd57e --- /dev/null +++ b/utbot-framework-test-java11/build.gradle @@ -0,0 +1,89 @@ +apply from: "${parent.projectDir}/gradle/include/jvm-project.gradle" + +compileKotlin { + kotlinOptions { + jvmTarget = JavaVersion.VERSION_11 + freeCompilerArgs += ["-Xallow-result-return-type", "-Xsam-conversions=class"] + } +} + +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} + +//noinspection GroovyAssignabilityCheck +repositories { + flatDir { + dirs 'dist' + } +} + +//noinspection GroovyAssignabilityCheck +configurations { + z3native +} + +dependencies { + api project(':utbot-api') + api project(':utbot-fuzzers') + api project(':utbot-core') + api project(':utbot-instrumentation') + api project(':utbot-summary') + api project(':utbot-framework-api') + + implementation project(':utbot-framework') + testImplementation project(":utbot-framework").sourceSets.test.output + testImplementation project(":utbot-core").sourceSets.test.output + + implementation "com.github.UnitTestBot:soot:${soot_commit_hash}" + + implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-kotlin', version: jackson_version + implementation group: 'org.sosy-lab', name: 'javasmt-solver-z3', version: javasmt_solver_z3_version + implementation group: 'com.github.curious-odd-man', name: 'rgxgen', version: rgxgen_version + implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: log4j2_version + implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlin_logging_version + implementation group: 'org.jacoco', name: 'org.jacoco.report', version: jacoco_version + implementation group: 'org.apache.commons', name: 'commons-text', version: apache_commons_text_version + // we need this for construction mocks from composite models + implementation group: 'org.mockito', name: 'mockito-core', version: '4.2.0' + + // To use JUnit4, comment out JUnit5 and uncomment JUnit4 dependencies here. Please also check "test" section + // testImplementation group: 'junit', name: 'junit', version: '4.13.1' + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.1' + testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.1' + + // used for testing code generation + testImplementation group: 'commons-io', name: 'commons-io', version: commons_io_version + testImplementation group: 'junit', name: 'junit', version: junit4_version + testImplementation group: 'org.junit.platform', name: 'junit-platform-console-standalone', version: junit4_platform_version + testImplementation group: 'org.antlr', name: 'antlr4', version: antlr_version + testImplementation group: 'org.mockito', name: 'mockito-core', version: mockito_version + testImplementation group: 'org.testng', name: 'testng', version: testng_version + testImplementation group: 'org.mockito', name: 'mockito-inline', version: mockito_inline_version + testImplementation group: 'com.google.guava', name: 'guava', version: guava_version + + testImplementation group: 'org.mockito', name: 'mockito-inline', version: mockito_inline_version + testImplementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: log4j2_version + + z3native group: 'com.microsoft.z3', name: 'z3-native-win64', version: z3_version, ext: 'zip' + z3native group: 'com.microsoft.z3', name: 'z3-native-linux64', version: z3_version, ext: 'zip' + z3native group: 'com.microsoft.z3', name: 'z3-native-osx', version: z3_version, ext: 'zip' +} + +test { + minHeapSize = "128m" + maxHeapSize = "2048m" + + jvmArgs '-XX:MaxHeapSize=2048m' + + // To use JUnit4, comment out useJUnitPlatform and uncomment useJUnit. Please also check "dependencies" section + //useJUnit() + useJUnitPlatform() { + excludeTags 'slow', 'IntegrationTest' + } + + if (System.getProperty('DEBUG', 'false') == 'true') { + jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009' + } +} diff --git a/utbot-framework-test-java11/src/main/java/org/utbot/examples/java11/collections/ToArrayWithGenerator.java b/utbot-framework-test-java11/src/main/java/org/utbot/examples/java11/collections/ToArrayWithGenerator.java new file mode 100644 index 0000000000..dde6fa3609 --- /dev/null +++ b/utbot-framework-test-java11/src/main/java/org/utbot/examples/java11/collections/ToArrayWithGenerator.java @@ -0,0 +1,134 @@ +package org.utbot.examples.java11.collections; + +import org.jetbrains.annotations.NotNull; + +import java.util.AbstractCollection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +public class ToArrayWithGenerator { + @SuppressWarnings("MismatchedReadAndWriteOfArray") + public boolean checkSetSize(int size) { + Set set = new HashSet<>(); + for (int i = 0; i < size; i++) { + set.add(i); + } + + Integer[] array = set.toArray(Integer[]::new); + return array.length == size; + } + + @SuppressWarnings({"SuspiciousToArrayCall", "MismatchedReadAndWriteOfArray"}) + public boolean checkSetSizeArrayStoreException(int size) { + Set set = new HashSet<>(); + for (int i = 0; i < size; i++) { + set.add(i); + } + + String[] array = set.toArray(String[]::new); + return array.length == size; + } + + public boolean checkListSize(int size) { + List integers = new LinkedList<>(); + for (int i = 0; i < size; i++) { + integers.add(i); + } + + return integers.toArray(Integer[]::new).length == size; + } + + @SuppressWarnings("MismatchedReadAndWriteOfArray") + public boolean checkMapKeysSize(int size) { + Map map = new HashMap<>(); + for (int i = 0; i < size; i++) { + map.put(i, "hello"); + } + + Integer[] keyArray = map.keySet().toArray(Integer[]::new); + return keyArray.length == size; + } + + @SuppressWarnings("MismatchedReadAndWriteOfArray") + public boolean checkMapValuesSize(int size) { + Map map = new HashMap<>(); + for (int i = 0; i < size; i++) { + map.put(i, "hello"); + } + + String[] valuesArray = map.values().toArray(String[]::new); + return valuesArray.length == size; + } + + @SuppressWarnings({"SuspiciousToArrayCall", "UnnecessaryLocalVariable"}) + public String[] getMapEntrySetArrayStoreException() { + Map namesMap = new HashMap<>(); + namesMap.put("Joe", "Jane"); + namesMap.put("Bill", "Anna"); + String[] names = namesMap.entrySet().toArray(String[]::new); + return names; + } + + public int getMapEntrySetSize() { + Map namesMap = new HashMap<>(); + namesMap.put("Joe", "Jane"); + namesMap.put("Bill", "Anna"); + Set> entries = namesMap.entrySet(); + return entries.toArray(Map.Entry[]::new).length; + } + + public int getCollectionArgumentSize(@NotNull Collection arg) { + return arg.toArray(Integer[]::new).length; + } + + public int getSetArgumentSize(@NotNull Set arg) { + return arg.toArray(Integer[]::new).length; + } + + public int getListArgumentSize(@NotNull List arg) { + return arg.toArray(Integer[]::new).length; + } + + public int getAbstractCollectionArgumentSize(@NotNull AbstractCollection arg) { + return arg.toArray(Integer[]::new).length; + } + + public int getGenericCollectionArgumentSize(@NotNull Collection arg) { + return arg.toArray(Object[]::new).length; + } + + public int countMatchingElements(@NotNull ArrayList arrayList) { + int size = arrayList.size(); + Integer[] array = arrayList.toArray(Integer[]::new); + if (array.length != size) { + return -1; + } + + int count = 0; + for (int i = 0; i < size; i++) { + Integer arrayElement = array[i]; + Integer listElement = arrayList.get(i); + if (arrayElement == null) { + if (listElement == null) { + count++; + } else { + return -2; + } + } else { + if (arrayElement.equals(listElement)) { + count++; + } + } + } + + return count; + } + +} diff --git a/utbot-framework-test-java11/src/test/kotlin/org/utbot/examples/java11/collections/ToArrayWithGeneratorTest.kt b/utbot-framework-test-java11/src/test/kotlin/org/utbot/examples/java11/collections/ToArrayWithGeneratorTest.kt new file mode 100644 index 0000000000..1100b3469e --- /dev/null +++ b/utbot-framework-test-java11/src/test/kotlin/org/utbot/examples/java11/collections/ToArrayWithGeneratorTest.kt @@ -0,0 +1,154 @@ +package org.utbot.examples.java11.collections + +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.api.CodegenLanguage +import org.utbot.testcheckers.between +import org.utbot.testcheckers.eq +import org.utbot.tests.infrastructure.CodeGeneration +import org.utbot.tests.infrastructure.DoNotCalculate +import org.utbot.tests.infrastructure.UtValueTestCaseChecker +import org.utbot.tests.infrastructure.ignoreExecutionsNumber +import org.utbot.tests.infrastructure.isException + +class ToArrayWithGeneratorTest : UtValueTestCaseChecker( + testClass = ToArrayWithGenerator::class, + testCodeGeneration = true, + languagePipelines = listOf( + CodeGenerationLanguageLastStage(CodegenLanguage.JAVA), + // TODO: We are generating Kotlin code for generic collections that will not compile + CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, lastStage = CodeGeneration) +) +) { + @Test + fun testCheckSetSize() { + check( + ToArrayWithGenerator::checkSetSize, + ignoreExecutionsNumber, + { size, result -> size < 0 && result == false }, + { size, result -> size >= 0 && result == true } + ) + } + + @Test + @Disabled("TODO: we can't yet model throwing ArrayStoreException") + fun testCheckSetSizeArrayStoreException() { + checkWithException( + ToArrayWithGenerator::checkSetSizeArrayStoreException, + eq(3), + { size, result -> size < 0 && result.isSuccess && result.getOrNull() == false }, + { size, result -> size == 0 && result.isSuccess && result.getOrNull() == true }, + { size, result -> size > 0 && result.isException() } + ) + } + + @Test + fun testCheckListSize() { + check( + ToArrayWithGenerator::checkListSize, + ignoreExecutionsNumber, + { size, result -> size < 0 && result == false }, + { size, result -> size >= 0 && result == true } + ) + } + + @Test + fun testCheckMapKeysSize() { + check( + ToArrayWithGenerator::checkMapKeysSize, + ignoreExecutionsNumber, + { size, result -> size < 0 && result == false }, + { size, result -> size >= 0 && result == true } + ) + } + + @Test + fun testCheckMapValuesSize() { + check( + ToArrayWithGenerator::checkMapValuesSize, + ignoreExecutionsNumber, + { size, result -> size < 0 && result == false }, + { size, result -> size >= 0 && result == true } + ) + } + + @Test + @Disabled("TODO: we can't yet model throwing ArrayStoreException") + fun testGetMapEntrySetArrayStoreException() { + checkWithException( + ToArrayWithGenerator::getMapEntrySetArrayStoreException, + eq(1), + { result -> result.isFailure && result.isException() }, + coverage = DoNotCalculate + ) + } + + @Test + fun testGetMapEntrySetSize() { + check( + ToArrayWithGenerator::getMapEntrySetSize, + eq(1), + { result -> result == 2 } + ) + } + + @Test + fun testGetCollectionArgumentSize() { + check( + ToArrayWithGenerator::getCollectionArgumentSize, + ignoreExecutionsNumber, + { arg, result -> result == arg.size } + ) + } + + @Test + fun testSetCollectionArgumentSize() { + check( + ToArrayWithGenerator::getSetArgumentSize, + ignoreExecutionsNumber, + { arg, result -> result == arg.size } + ) + } + + @Test + fun testListCollectionArgumentSize() { + check( + ToArrayWithGenerator::getListArgumentSize, + ignoreExecutionsNumber, + { arg, result -> result == arg.size } + ) + } + + @Test + @Disabled("TODO: this test takes too long and results in non-instantiable concrete type substitutions") + fun testGetAbstractCollectionArgumentSize() { + check( + ToArrayWithGenerator::getAbstractCollectionArgumentSize, + ignoreExecutionsNumber, + { arg, result -> result == arg.size } + ) + } + + @Test + @Disabled("TODO: translate of UtArrayApplyForAll expression (#630)") + fun testGetGenericCollectionArgumentSize() { + check( + ToArrayWithGenerator::getGenericCollectionArgumentSize, + ignoreExecutionsNumber, + { arg, result -> result == arg.size }, + coverage = DoNotCalculate + ) + } + + @Test + fun testCountMatchingElements() { + check( + ToArrayWithGenerator::countMatchingElements, + between(3..4), + { arg, result -> arg.isEmpty() && result == 0 }, + { arg, result -> arg.contains(null) && result == arg.size }, + { arg, result -> arg.isNotEmpty() && !arg.contains(null) && result == arg.size }, + coverage = DoNotCalculate // TODO: investigate the incomplete coverage + ) + } +} diff --git a/utbot-framework-test-java11/src/test/resources/junit-platform.properties b/utbot-framework-test-java11/src/test/resources/junit-platform.properties new file mode 100644 index 0000000000..b059a65dc4 --- /dev/null +++ b/utbot-framework-test-java11/src/test/resources/junit-platform.properties @@ -0,0 +1 @@ +junit.jupiter.extensions.autodetection.enabled=true \ No newline at end of file diff --git a/utbot-framework-test-java11/src/test/resources/log4j2.xml b/utbot-framework-test-java11/src/test/resources/log4j2.xml new file mode 100644 index 0000000000..33db726dc9 --- /dev/null +++ b/utbot-framework-test-java11/src/test/resources/log4j2.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/utbot-framework-test-java11/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/utbot-framework-test-java11/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 0000000000..ca6ee9cea8 --- /dev/null +++ b/utbot-framework-test-java11/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline \ No newline at end of file diff --git a/utbot-framework-test-java11/src/test/resources/services/org.junit.jupiter.api.extension.Extension b/utbot-framework-test-java11/src/test/resources/services/org.junit.jupiter.api.extension.Extension new file mode 100644 index 0000000000..3885d45734 --- /dev/null +++ b/utbot-framework-test-java11/src/test/resources/services/org.junit.jupiter.api.extension.Extension @@ -0,0 +1 @@ +org.utbot.framework.JUnitSetup \ No newline at end of file diff --git a/utbot-framework-test/build.gradle b/utbot-framework-test/build.gradle index 363c57075c..5e76bc4f66 100644 --- a/utbot-framework-test/build.gradle +++ b/utbot-framework-test/build.gradle @@ -73,7 +73,6 @@ dependencies { z3native group: 'com.microsoft.z3', name: 'z3-native-osx', version: z3_version, ext: 'zip' } - test { minHeapSize = "128m" diff --git a/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/AbstractCollection.java b/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/AbstractCollection.java index 82ba954be4..dd45f4228f 100644 --- a/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/AbstractCollection.java +++ b/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/AbstractCollection.java @@ -1,5 +1,6 @@ package org.utbot.engine.overrides.collections; +import java.util.function.IntFunction; import org.utbot.api.annotation.UtClassMock; import static org.utbot.api.mock.UtMock.makeSymbolic; @@ -10,4 +11,11 @@ public abstract class AbstractCollection implements java.util.Collection { public String toString() { return makeSymbolic(); } + + @SuppressWarnings("Since15") + public T[] toArray(IntFunction generator) { + final int size = size(); + T[] data = generator.apply(size); + return toArray(data); + } } diff --git a/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/Collection.java b/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/Collection.java index 8f7edebe37..f4244291f6 100644 --- a/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/Collection.java +++ b/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/Collection.java @@ -1,8 +1,12 @@ package org.utbot.engine.overrides.collections; +import org.jetbrains.annotations.NotNull; import org.utbot.api.annotation.UtClassMock; +import org.utbot.api.mock.UtMock; import org.utbot.engine.overrides.stream.UtStream; +import java.util.Objects; +import java.util.function.IntFunction; import java.util.stream.Stream; @UtClassMock(target = java.util.Collection.class, internalUsage = true) @@ -24,4 +28,11 @@ default Stream stream() { return new UtStream<>((E[]) data, size); } + + @SuppressWarnings("Since15") + default T[] toArray(@NotNull IntFunction generator) { + Objects.requireNonNull(generator); + T[] data = generator.apply(0); + return toArray(data); + } } diff --git a/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/UtHashMap.java b/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/UtHashMap.java index f3a9b22405..aab78d9c2d 100644 --- a/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/UtHashMap.java +++ b/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/UtHashMap.java @@ -11,10 +11,14 @@ import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Function; +import java.util.function.IntFunction; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.utbot.engine.overrides.UtArrayMock; import static org.utbot.api.mock.UtMock.assume; +import static org.utbot.api.mock.UtMock.assumeOrExecuteConcretely; import static org.utbot.api.mock.UtMock.makeSymbolic; import static org.utbot.engine.overrides.UtOverrideMock.alreadyVisited; import static org.utbot.engine.overrides.UtOverrideMock.doesntThrow; @@ -446,31 +450,50 @@ public Set keySet() { } public final class LinkedKeySet extends AbstractSet { - public final int size() { + public int size() { preconditionCheck(); return keys.end; } - public final void clear() { + public void clear() { preconditionCheck(); UtHashMap.this.clear(); } @NotNull - public final Iterator iterator() { + public Iterator iterator() { preconditionCheck(); return new LinkedKeyIterator(); } - public final boolean contains(Object o) { + public boolean contains(Object o) { preconditionCheck(); return containsKey(o); } - public final boolean remove(Object key) { + public boolean remove(Object key) { preconditionCheck(); return UtHashMap.this.remove(key) != null; } + + public Object[] toArray() { + preconditionCheck(); + return keys.toArray(keys.begin, keys.end); + } + + public T[] toArray(@NotNull T[] a) { + preconditionCheck(); + Object[] data = toArray(); + UtArrayMock.arraycopy(data, 0, a, 0, data.length); + return a; + } + + @SuppressWarnings("Since15") + public T[] toArray(@NotNull IntFunction generator) { + preconditionCheck(); + T[] a = generator.apply(size()); + return toArray(a); + } } @NotNull @@ -481,26 +504,55 @@ public Collection values() { } public final class LinkedValues extends AbstractCollection { - public final int size() { + public int size() { preconditionCheck(); return keys.end; } - public final void clear() { + public void clear() { preconditionCheck(); UtHashMap.this.clear(); } @NotNull - public final Iterator iterator() { + public Iterator iterator() { preconditionCheck(); return new LinkedValueIterator(); } - public final boolean contains(Object o) { + public boolean contains(Object o) { preconditionCheck(); return containsValue(o); } + + @NotNull + @Override + public Object[] toArray() { + preconditionCheck(); + final int size = size(); + final int end = keys.end; + assumeOrExecuteConcretely(end < 3); + Object[] data = new Object[size]; + for (int i = 0; i < end; i++) { + data[i] = values.select(keys.get(i)); + } + return data; + } + + @Override + public T[] toArray(@NotNull T[] a) { + preconditionCheck(); + Object[] data = toArray(); + UtArrayMock.arraycopy(data, 0, a, 0, data.length); + return a; + } + + @SuppressWarnings("Since15") + public T[] toArray(@NotNull IntFunction generator) { + preconditionCheck(); + T[] a = generator.apply(size()); + return toArray(a); + } } @NotNull @@ -511,23 +563,23 @@ public Set> entrySet() { } public final class LinkedEntrySet extends AbstractSet> { - public final int size() { + public int size() { preconditionCheck(); return keys.end; } - public final void clear() { + public void clear() { preconditionCheck(); UtHashMap.this.clear(); } @NotNull - public final Iterator> iterator() { + public Iterator> iterator() { preconditionCheck(); return new LinkedEntryIterator(); } - public final boolean contains(Object o) { + public boolean contains(Object o) { preconditionCheck(); if (!(o instanceof Map.Entry)) return false; @@ -537,7 +589,7 @@ public final boolean contains(Object o) { return index != -1 && Objects.equals(e.getValue(), values.select(keys.get(index))); } - public final boolean remove(Object o) { + public boolean remove(Object o) { preconditionCheck(); if (o instanceof Map.Entry) { Map.Entry e = (Map.Entry) o; @@ -551,6 +603,35 @@ public final boolean remove(Object o) { } return false; } + + @NotNull + @Override + public Object[] toArray() { + preconditionCheck(); + Object[] data = new Object[size()]; + for (int index = keys.begin; index < keys.end; index++) { + data[index] = new Entry(index); + } + return data; + } + + @SuppressWarnings("unchecked") + @NotNull + @Override + public T[] toArray(@NotNull T[] a) { + preconditionCheck(); + T[] data = (T[]) toArray(); + UtArrayMock.arraycopy(data, 0, a, 0, size()); + return a; + } + + @SuppressWarnings("Since15") + @NotNull + public T[] toArray(IntFunction generator) { + preconditionCheck(); + T[] a = generator.apply(size()); + return toArray(a); + } } // TODO rewrite it JIRA:1604 @@ -696,7 +777,7 @@ public final V next() { public final class LinkedEntryIterator extends LinkedHashIterator implements Iterator> { - public final Map.Entry next() { + public Map.Entry next() { preconditionCheck(); return new Entry(nextEntry()); } diff --git a/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/UtHashSet.java b/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/UtHashSet.java index 6daf394505..25bffe9f4f 100644 --- a/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/UtHashSet.java +++ b/utbot-framework/src/main/java/org/utbot/engine/overrides/collections/UtHashSet.java @@ -138,8 +138,7 @@ public Object[] toArray() { @SuppressWarnings({"unchecked"}) @NotNull @Override - public T[] toArray(@NotNull T[] a) { - Objects.requireNonNull(a); + public T[] toArray(T[] a) { preconditionCheck(); if (a.length < elementData.end) { return (T[]) toArray(); diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/Resolver.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/Resolver.kt index 01687fee75..057779438d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/Resolver.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/Resolver.kt @@ -800,6 +800,13 @@ class Resolver( } val evaluatedType = workaround(HACK) { memory.findTypeForArrayOrNull(instance.addr) ?: instance.type } + + // Instead of previous line, we can try to get element type from the solver, but something will break + // val evaluatedType = holder.constructTypeOrNull(instance.addr, instance.type) as? ArrayType ?: instance.type + + // GENERAL IDEA: check for ArrayStoreException when processing array store, not `toArray` or like. + // See as ClassCastException is implemented (and NPE as well) + val evaluatedBaseType = evaluatedType.baseType val chunkId = typeRegistry.arrayChunkId(evaluatedType)