Skip to content

Commit 1db6355

Browse files
Fix broken compilation after mighration to java 17 (#1904)
kotlin.Streams.toList clashes with java.util.stream.Stream#toList when both project and Gradle are under Java 17
1 parent e611e47 commit 1db6355

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/BaseStreamExampleTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import org.utbot.testing.ignoreExecutionsNumber
1717
import org.utbot.testing.isException
1818
import java.util.Optional
1919
import java.util.stream.Stream
20-
import kotlin.streams.toList
20+
import org.utbot.testing.asList
2121

2222
// TODO 1 instruction is always uncovered https://github.com/UnitTestBot/UTBotJava/issues/193
2323
// TODO failed Kotlin compilation (generics) JIRA:1332
@@ -35,7 +35,7 @@ class BaseStreamExampleTest : UtValueTestCaseChecker(
3535
check(
3636
BaseStreamExample::returningStreamAsParameterExample,
3737
eq(1),
38-
{ s, r -> s != null && s.toList() == r!!.toList() },
38+
{ s, r -> s != null && s.asList() == r!!.asList() },
3939
coverage = FullWithAssumptions(assumeCallsNumber = 1)
4040
)
4141
}

utbot-framework-test/src/test/kotlin/org/utbot/examples/stream/StreamsAsMethodResultExampleTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.utbot.testing.FullWithAssumptions
99
import org.utbot.testing.UtValueTestCaseChecker
1010
import org.utbot.testing.isException
1111
import kotlin.streams.toList
12+
import org.utbot.testing.asList
1213

1314
// TODO 1 instruction is always uncovered https://github.com/UnitTestBot/UTBotJava/issues/193
1415
// TODO failed Kotlin compilation (generics) JIRA:1332
@@ -25,8 +26,8 @@ class StreamsAsMethodResultExampleTest : UtValueTestCaseChecker(
2526
check(
2627
StreamsAsMethodResultExample::returningStreamExample,
2728
eq(2),
28-
{ c, r -> c.isEmpty() && c == r!!.toList() },
29-
{ c, r -> c.isNotEmpty() && c == r!!.toList() },
29+
{ c, r -> c.isEmpty() && c == r!!.asList() },
30+
{ c, r -> c.isNotEmpty() && c == r!!.asList() },
3031
coverage = FullWithAssumptions(assumeCallsNumber = 1)
3132
)
3233
}

utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ import org.utbot.framework.plugin.api.Step
2929
import org.utbot.summary.comment.isLoopStatement
3030
import java.util.LinkedList
3131
import java.util.Queue
32+
import java.util.stream.Collectors
33+
import java.util.stream.Stream
3234
import kotlin.Int.Companion.MAX_VALUE
3335
import kotlin.math.abs
34-
import kotlin.streams.toList
3536
import soot.Unit
3637
import soot.Value
3738
import soot.jimple.internal.JCaughtExceptionRef
@@ -76,11 +77,16 @@ class JimpleToASTMap(stmts: Iterable<Unit>, methodDeclaration: MethodDeclaration
7677
alignNonAlignedReturns()
7778
}
7879

80+
/**
81+
* Avoid conflict with java.util.stream.Stream.toList (available since Java 16 only)
82+
*/
83+
private fun <T> Stream<T>.asList(): List<T> = collect(Collectors.toList<T>())
84+
7985
/**
8086
* Function that maps statements inside of ternary conditions to correct AST nodes
8187
*/
8288
private fun mapTernaryConditional(methodDeclaration: MethodDeclaration, stmts: Iterable<Unit>) {
83-
for (condExpr in methodDeclaration.stream().toList().filterIsInstance<ConditionalExpr>()) {
89+
for (condExpr in methodDeclaration.stream().asList().filterIsInstance<ConditionalExpr>()) {
8490
val begin = condExpr.begin.orElse(null)
8591
val end = condExpr.end.orElse(null)
8692
if (begin == null || end == null) continue
@@ -123,7 +129,7 @@ class JimpleToASTMap(stmts: Iterable<Unit>, methodDeclaration: MethodDeclaration
123129
* Node is valid if there is only one return statement inside of it
124130
*/
125131
private fun validateReturnASTNode(returnNode: Node): Node {
126-
val returns = returnNode.stream().filter { it is ReturnStmt }.toList()
132+
val returns = returnNode.stream().filter { it is ReturnStmt }.asList()
127133
if (returns.size == 1) return returns[0]
128134
return returnNode
129135
}
@@ -147,17 +153,17 @@ class JimpleToASTMap(stmts: Iterable<Unit>, methodDeclaration: MethodDeclaration
147153
val loopList = mutableListOf<Node>()
148154
when (loop) {
149155
is ForStmt -> {
150-
loopList.addAll(loop.initialization.stream().toList())
151-
val compare = loop.compare.orElse(null)?.stream()?.toList()
156+
loopList.addAll(loop.initialization.stream().asList())
157+
val compare = loop.compare.orElse(null)?.stream()?.asList()
152158
if (compare != null) loopList.addAll(compare)
153-
loopList.addAll(loop.update.flatMap { it.stream().toList() })
159+
loopList.addAll(loop.update.flatMap { it.stream().asList() })
154160
}
155161
is WhileStmt -> {
156-
loopList.addAll(loop.condition.stream().toList())
162+
loopList.addAll(loop.condition.stream().asList())
157163
}
158164
is ForEachStmt -> {
159-
loopList.addAll(loop.iterable.stream().toList())
160-
loopList.addAll(loop.variable.stream().toList())
165+
loopList.addAll(loop.iterable.stream().asList())
166+
loopList.addAll(loop.variable.stream().asList())
161167
}
162168
}
163169
for (stmt in stmtToASTNode.filter { it.value in loopList }.map { it.key }) stmtToASTNode[stmt] = loop

utbot-testing/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import org.utbot.testcheckers.ExecutionsNumberMatcher
4747
import java.io.File
4848
import java.nio.file.Path
4949
import java.nio.file.Paths
50+
import java.util.stream.Collectors
51+
import java.util.stream.Stream
5052
import kotlin.reflect.KClass
5153
import kotlin.reflect.KFunction
5254
import kotlin.reflect.KFunction0
@@ -2041,3 +2043,8 @@ inline fun <reified T> withSettingsFromTestFrameworkConfiguration(
20412043
TestCodeGeneratorPipeline.currentTestFrameworkConfiguration = previousConfig
20422044
}
20432045
}
2046+
2047+
/**
2048+
* Avoid conflict with java.util.stream.Stream.toList (available since Java 16 only)
2049+
*/
2050+
fun <T> Stream<T>.asList(): List<T> = collect(Collectors.toList<T>())

0 commit comments

Comments
 (0)