Skip to content

Remove error from generics processing #1646

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

Merged
merged 1 commit into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.utbot.examples.types
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.utbot.testcheckers.eq
import org.utbot.testing.DoNotCalculate
import org.utbot.testing.UtValueTestCaseChecker
import org.utbot.testing.ignoreExecutionsNumber

Expand All @@ -13,7 +14,7 @@ internal class GenericsTest : UtValueTestCaseChecker(
@Test
fun mapAsParameterTest() {
check(
Generics::mapAsParameter,
Generics<*>::mapAsParameter,
eq(2),
{ map, _ -> map == null },
{ map, r -> map != null && r == "value" },
Expand All @@ -24,7 +25,7 @@ internal class GenericsTest : UtValueTestCaseChecker(
@Disabled("https://github.com/UnitTestBot/UTBotJava/issues/1620 wrong equals")
fun genericAsFieldTest() {
check(
Generics::genericAsField,
Generics<*>::genericAsField,
ignoreExecutionsNumber,
{ obj, r -> obj?.field == null && r == false },
// we can cover this line with any of these two conditions
Expand All @@ -35,7 +36,7 @@ internal class GenericsTest : UtValueTestCaseChecker(
@Test
fun mapAsStaticFieldTest() {
check(
Generics::mapAsStaticField,
Generics<*>::mapAsStaticField,
ignoreExecutionsNumber,
{ r -> r == "value" },
)
Expand All @@ -44,7 +45,7 @@ internal class GenericsTest : UtValueTestCaseChecker(
@Test
fun mapAsNonStaticFieldTest() {
check(
Generics::mapAsNonStaticField,
Generics<*>::mapAsNonStaticField,
ignoreExecutionsNumber,
{ map, _ -> map == null },
{ map, r -> map != null && r == "value" },
Expand All @@ -54,10 +55,20 @@ internal class GenericsTest : UtValueTestCaseChecker(
@Test
fun methodWithRawTypeTest() {
check(
Generics::methodWithRawType,
Generics<*>::methodWithRawType,
eq(2),
{ map, _ -> map == null },
{ map, r -> map != null && r == "value" },
)
}

@Test
fun testMethodWithArrayTypeBoundary() {
checkWithException(
Generics<*>::methodWithArrayTypeBoundary,
eq(1),
{ r -> r.exceptionOrNull() is java.lang.NullPointerException },
coverage = DoNotCalculate
)
}
}
6 changes: 4 additions & 2 deletions utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,8 @@ class Traverser(

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

val upperBoundsTypes = typeResolver.intersectInheritors(upperBounds)
Expand All @@ -1124,7 +1125,8 @@ class Traverser(

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

val upperBoundsTypes = typeResolver.intersectInheritors(upperBounds)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.utbot.examples.types;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Generics {
public class Generics<T> {
public boolean genericAsField(CollectionAsField<String> object) {
if (object != null && object.field != null) {
return object.field.equals("abc");
Expand Down Expand Up @@ -38,4 +40,18 @@ public String methodWithRawType(Map map) {
private Map<String, String> nestedMethodWithGenericInfo(Map<String, String> map) {
return map;
}

public int methodWithArrayTypeBoundary() {
return new ArrayTypeParameters<T>().methodWithArrayTypeBoundary(null);
}
}

class ArrayTypeParameters<T> {
public int methodWithArrayTypeBoundary(List<? extends T[]> list) {
if (list.isEmpty()) {
return -1;
}

return 1;
}
}