Skip to content

Commit ed0e49f

Browse files
DaniilStepanovlehvolk
authored andcommitted
Juliet is working
1 parent d2538ff commit ed0e49f

7 files changed

Lines changed: 222 additions & 11 deletions

File tree

jacodb-analysis/src/test/kotlin/org/jacodb/analysis/impl/NpeAnalysisTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class NpeAnalysisTest : BaseAnalysisTest() {
6060

6161
@Test
6262
fun `analyze simple NPE`() {
63-
testOneMethod<NpeExamples>("npeOnLength", listOf("%3 = %2.length()"))
63+
testOneMethod<NpeExamples>("npeOnLength", listOf("%3 = %0.length()"))
6464
}
6565

6666
@Test
@@ -72,7 +72,7 @@ class NpeAnalysisTest : BaseAnalysisTest() {
7272
fun `analyze NPE after fun with two exits`() {
7373
testOneMethod<NpeExamples>(
7474
"npeAfterTwoExits",
75-
listOf("%4 = %2.length()", "%5 = %3.length()")
75+
listOf("%4 = %0.length()", "%5 = %1.length()")
7676
)
7777
}
7878

jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/RawInstListBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class RawInstListBuilder(
474474
?.desc
475475
?.typeName()
476476

477-
return if (declaredTypeName != null && !declaredTypeName.isPrimitive) {
477+
return if (declaredTypeName != null && !declaredTypeName.isPrimitive && !typeName.isArray) {
478478
JcRawLocalVar("%${localCounter++}", declaredTypeName)
479479
} else {
480480
JcRawLocalVar("%${localCounter++}", typeName)

jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/Simplifier.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ internal class Simplifier {
5555
val assignmentsMap = computeAssignments(instructionList)
5656
val replacements = assignmentsMap
5757
.filter { (assignmentsMap[it.value.first()]?.let { it.size == 1 } ?: true) }
58-
.filterValues { it.size == 1 && it.first() is JcRawLocalVar }
58+
.filterValues { it.first() is JcRawLocalVar && it.drop(1).all { it !is JcRawLocalVar } }
5959
.map { it.key to it.value.first() }
6060
.toMap()
6161
instructionList = instructionList

jacodb-core/src/test/kotlin/org/jacodb/testing/cfg/IRTest.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ import org.jacodb.impl.cfg.util.ExprMapper
3434
import org.jacodb.impl.features.classpaths.ClasspathCache
3535
import org.jacodb.impl.features.classpaths.StringConcatSimplifier
3636
import org.jacodb.impl.fs.JarLocation
37-
import org.jacodb.testing.WithDB
38-
import org.jacodb.testing.guavaLib
39-
import org.jacodb.testing.kotlinxCoroutines
37+
import org.jacodb.testing.*
4038
import org.junit.jupiter.api.AfterEach
4139
import org.junit.jupiter.api.Assertions.*
4240
import org.junit.jupiter.api.Test
@@ -306,10 +304,13 @@ class IRTest : BaseInstructionsTest() {
306304
// todo: make this test green
307305
@Test
308306
fun `get ir of kotlinx-coroutines`() {
309-
// testClass(cp.findClass("kotlinx.coroutines.ThreadContextElementKt"))
310307
runAlongLib(kotlinxCoroutines, false)
311308
}
312309

310+
@Test
311+
fun `get ir of kotlin stdlib`() {
312+
runAlongLib(kotlinStdLib, false)
313+
}
313314

314315

315316
@AfterEach

jacodb-core/src/test/kotlin/org/jacodb/testing/cfg/KotlinInstructionsTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ class KotlinInstructionsTest: BaseInstructionsTest() {
5151
@Test
5252
fun `kotlin try catch finally`() = runKotlinTest(TryCatchFinally::class.java.name, muteGraphChecker = true)
5353

54+
@Test
55+
fun `kotlin try catch finally 2`() = runKotlinTest(TryCatchFinally2::class.java.name, muteGraphChecker = true)
56+
57+
@Test
58+
fun `kotlin try catch finally 3`() = runKotlinTest(TryCatchFinally3::class.java.name, muteGraphChecker = true)
59+
60+
@Test
61+
fun `kotlin try catch finally 4`() = runKotlinTest(TryCatchFinally4::class.java.name, muteGraphChecker = true)
62+
5463
@Test
5564
fun `kotlin method with exception`() = runKotlinTest(InvokeMethodWithException::class.java.name)
5665

jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/LibrariesMixin.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ val kotlinxCoroutines: File
4141
}
4242
}
4343

44+
val kotlinStdLib: File
45+
get() {
46+
val kotlinStdLib = classpath.first { it.contains("/kotlin-stdlib/") }
47+
return File(kotlinStdLib).also {
48+
Assertions.assertTrue(it.isFile && it.exists())
49+
}
50+
}
51+
4452
val allJars: List<File>
4553
get() {
4654
return classpath.filter { it.endsWith(".jar") }.map { File(it) }

jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/cfg/TryCatchFinally.kt

Lines changed: 196 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,210 @@ class TryCatchFinally {
2121
fun f(): Int {
2222
try {
2323
return 0
24-
}
25-
finally {
24+
} finally {
2625
try { // culprit ?? remove this try-catch and it works.
2726
} catch (ignore: Exception) {
2827
}
2928
}
3029
}
3130

3231
fun box(): String {
33-
if (f() != 0) return "fail1"
32+
if (f() != 0) return "fail1"
33+
34+
return "OK"
35+
}
36+
37+
}
38+
39+
class TryCatchFinally2 {
40+
fun test1(): String {
41+
var s = "";
42+
try {
43+
try {
44+
s += "Try";
45+
throw Exception()
46+
} catch (x: Exception) {
47+
s += "Catch";
48+
throw x
49+
} finally {
50+
s += "Finally";
51+
}
52+
} catch (x: Exception) {
53+
return s
54+
}
55+
}
56+
57+
fun test2(): String {
58+
var s = "";
59+
60+
try {
61+
s += "Try";
62+
throw Exception()
63+
} catch (x: Exception) {
64+
s += "Catch";
65+
} finally {
66+
s += "Finally";
67+
}
68+
69+
return s
70+
}
71+
72+
73+
fun box(): String {
74+
if (test1() != "TryCatchFinally") return "fail1: ${test1()}"
75+
76+
if (test2() != "TryCatchFinally") return "fail2: ${test2()}"
77+
78+
return "OK"
79+
}
80+
81+
}
82+
83+
class TryCatchFinally3 {
84+
fun unsupportedEx() {
85+
if (true) throw UnsupportedOperationException()
86+
}
87+
88+
fun runtimeEx() {
89+
if (true) throw RuntimeException()
90+
}
91+
92+
fun test1WithFinally(): String {
93+
var s = "";
94+
try {
95+
try {
96+
s += "Try";
97+
unsupportedEx()
98+
} finally {
99+
s += "Finally"
100+
}
101+
} catch (x: RuntimeException) {
102+
return s
103+
}
104+
return s + "Failed"
105+
}
106+
107+
108+
fun test2WithFinally(): String {
109+
var s = "";
110+
try {
111+
try {
112+
s += "Try";
113+
unsupportedEx()
114+
return s
115+
} finally {
116+
s += "Finally"
117+
}
118+
} catch (x: RuntimeException) {
119+
return s
120+
}
121+
}
122+
123+
fun box(): String {
124+
if (test1WithFinally() != "TryFinally") return "fail2: ${test1WithFinally()}"
125+
126+
if (test2WithFinally() != "TryFinally") return "fail4: ${test2WithFinally()}"
127+
return "OK"
128+
}
129+
}
130+
131+
class TryCatchFinally4{
132+
fun unsupportedEx() {
133+
if (true) throw UnsupportedOperationException()
134+
}
135+
136+
fun runtimeEx() {
137+
if (true) throw RuntimeException()
138+
}
139+
140+
fun test1() : String {
141+
var s = "";
142+
try {
143+
try {
144+
s += "Try";
145+
unsupportedEx()
146+
} catch (x : UnsupportedOperationException) {
147+
s += "Catch";
148+
runtimeEx()
149+
} catch (e: RuntimeException) {
150+
s += "WrongCatch"
151+
}
152+
} catch (x : RuntimeException) {
153+
return s
154+
}
155+
return s + "Failed"
156+
}
157+
158+
fun test1WithFinally() : String {
159+
var s = "";
160+
try {
161+
try {
162+
s += "Try";
163+
unsupportedEx()
164+
} catch (x : UnsupportedOperationException) {
165+
s += "Catch";
166+
runtimeEx()
167+
} catch (e: RuntimeException) {
168+
s += "WrongCatch"
169+
} finally {
170+
s += "Finally"
171+
}
172+
} catch (x : RuntimeException) {
173+
return s
174+
}
175+
return s + "Failed"
176+
}
177+
178+
fun test2() : String {
179+
var s = "";
180+
try {
181+
try {
182+
s += "Try";
183+
unsupportedEx()
184+
return s
185+
} catch (x : UnsupportedOperationException) {
186+
s += "Catch";
187+
runtimeEx()
188+
return s
189+
} catch (e: RuntimeException) {
190+
s += "WrongCatch"
191+
}
192+
} catch (x : RuntimeException) {
193+
return s
194+
}
195+
return s + "Failed"
196+
}
197+
198+
fun test2WithFinally() : String {
199+
var s = "";
200+
try {
201+
try {
202+
s += "Try";
203+
unsupportedEx()
204+
return s
205+
} catch (x : UnsupportedOperationException) {
206+
s += "Catch";
207+
runtimeEx()
208+
return s
209+
} catch (e: RuntimeException) {
210+
s += "WrongCatch"
211+
} finally {
212+
s += "Finally"
213+
}
214+
} catch (x : RuntimeException) {
215+
return s
216+
}
217+
return s + "Failed"
218+
}
219+
220+
221+
222+
fun box() : String {
223+
if (test1() != "TryCatch") return "fail1: ${test1()}"
224+
if (test1WithFinally() != "TryCatchFinally") return "fail2: ${test1WithFinally()}"
34225

226+
if (test2() != "TryCatch") return "fail3: ${test2()}"
227+
if (test2WithFinally() != "TryCatchFinally") return "fail4: ${test2WithFinally()}"
35228
return "OK"
36229
}
37230

0 commit comments

Comments
 (0)