Skip to content

Commit 6fa3e1b

Browse files
authored
Remove error from generics processing (#1646)
1 parent 3d89fdf commit 6fa3e1b

File tree

3 files changed

+37
-8
lines changed
  • utbot-framework/src/main/kotlin/org/utbot/engine
  • utbot-framework-test/src/test/kotlin/org/utbot/examples/types
  • utbot-sample/src/main/java/org/utbot/examples/types

3 files changed

+37
-8
lines changed

utbot-framework-test/src/test/kotlin/org/utbot/examples/types/GenericsTest.kt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.utbot.examples.types
33
import org.junit.jupiter.api.Disabled
44
import org.junit.jupiter.api.Test
55
import org.utbot.testcheckers.eq
6+
import org.utbot.testing.DoNotCalculate
67
import org.utbot.testing.UtValueTestCaseChecker
78
import org.utbot.testing.ignoreExecutionsNumber
89

@@ -13,7 +14,7 @@ internal class GenericsTest : UtValueTestCaseChecker(
1314
@Test
1415
fun mapAsParameterTest() {
1516
check(
16-
Generics::mapAsParameter,
17+
Generics<*>::mapAsParameter,
1718
eq(2),
1819
{ map, _ -> map == null },
1920
{ map, r -> map != null && r == "value" },
@@ -24,7 +25,7 @@ internal class GenericsTest : UtValueTestCaseChecker(
2425
@Disabled("https://github.com/UnitTestBot/UTBotJava/issues/1620 wrong equals")
2526
fun genericAsFieldTest() {
2627
check(
27-
Generics::genericAsField,
28+
Generics<*>::genericAsField,
2829
ignoreExecutionsNumber,
2930
{ obj, r -> obj?.field == null && r == false },
3031
// we can cover this line with any of these two conditions
@@ -35,7 +36,7 @@ internal class GenericsTest : UtValueTestCaseChecker(
3536
@Test
3637
fun mapAsStaticFieldTest() {
3738
check(
38-
Generics::mapAsStaticField,
39+
Generics<*>::mapAsStaticField,
3940
ignoreExecutionsNumber,
4041
{ r -> r == "value" },
4142
)
@@ -44,7 +45,7 @@ internal class GenericsTest : UtValueTestCaseChecker(
4445
@Test
4546
fun mapAsNonStaticFieldTest() {
4647
check(
47-
Generics::mapAsNonStaticField,
48+
Generics<*>::mapAsNonStaticField,
4849
ignoreExecutionsNumber,
4950
{ map, _ -> map == null },
5051
{ map, r -> map != null && r == "value" },
@@ -54,10 +55,20 @@ internal class GenericsTest : UtValueTestCaseChecker(
5455
@Test
5556
fun methodWithRawTypeTest() {
5657
check(
57-
Generics::methodWithRawType,
58+
Generics<*>::methodWithRawType,
5859
eq(2),
5960
{ map, _ -> map == null },
6061
{ map, r -> map != null && r == "value" },
6162
)
6263
}
64+
65+
@Test
66+
fun testMethodWithArrayTypeBoundary() {
67+
checkWithException(
68+
Generics<*>::methodWithArrayTypeBoundary,
69+
eq(1),
70+
{ r -> r.exceptionOrNull() is java.lang.NullPointerException },
71+
coverage = DoNotCalculate
72+
)
73+
}
6374
}

utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,8 @@ class Traverser(
11241124

11251125
if (allTypes.any { it is GenericArrayType }) {
11261126
val errorTypes = allTypes.filterIsInstance<GenericArrayType>()
1127-
TODO("we do not support GenericArrayTypeImpl yet, and $errorTypes found. SAT-1446")
1127+
logger.warn { "we do not support GenericArrayTypeImpl yet, and $errorTypes found. SAT-1446" }
1128+
return
11281129
}
11291130

11301131
val upperBoundsTypes = typeResolver.intersectInheritors(upperBounds)
@@ -1137,7 +1138,8 @@ class Traverser(
11371138

11381139
if (upperBounds.any { it is GenericArrayType }) {
11391140
val errorTypes = upperBounds.filterIsInstance<GenericArrayType>()
1140-
TODO("we do not support GenericArrayType yet, and $errorTypes found. SAT-1446")
1141+
logger.warn { "we do not support GenericArrayType yet, and $errorTypes found. SAT-1446" }
1142+
return
11411143
}
11421144

11431145
val upperBoundsTypes = typeResolver.intersectInheritors(upperBounds)

utbot-sample/src/main/java/org/utbot/examples/types/Generics.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.utbot.examples.types;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
35
import java.util.Map;
46

5-
public class Generics {
7+
public class Generics<T> {
68
public boolean genericAsField(CollectionAsField<String> object) {
79
if (object != null && object.field != null) {
810
return object.field.equals("abc");
@@ -38,4 +40,18 @@ public String methodWithRawType(Map map) {
3840
private Map<String, String> nestedMethodWithGenericInfo(Map<String, String> map) {
3941
return map;
4042
}
43+
44+
public int methodWithArrayTypeBoundary() {
45+
return new ArrayTypeParameters<T>().methodWithArrayTypeBoundary(null);
46+
}
47+
}
48+
49+
class ArrayTypeParameters<T> {
50+
public int methodWithArrayTypeBoundary(List<? extends T[]> list) {
51+
if (list.isEmpty()) {
52+
return -1;
53+
}
54+
55+
return 1;
56+
}
4157
}

0 commit comments

Comments
 (0)