Skip to content

Commit 485eab1

Browse files
committed
Ensure that there are no references to atomicfu in classes
* Updated to 0.12.7 version of atmoicfu with fixes. * Added test that that is no references to atomicfu in any of the resulting class files. Fixes #1155
1 parent b81f5f0 commit 485eab1

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

binary-compatibility-validator/test/PublicApiTest.kt

+29-3
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@ class PublicApiTest(
4343
@Test
4444
fun testApi() {
4545
val libsDir = File("../$rootDir/$moduleName/build/libs").absoluteFile.normalize()
46-
val jarFile = getJarPath(libsDir)
46+
val jarPath = getJarPath(libsDir)
4747
val kotlinJvmMappingsFiles = listOf(libsDir.resolve("../visibilities.json"))
4848
val visibilities =
4949
kotlinJvmMappingsFiles
5050
.map { readKotlinVisibilities(it) }
5151
.reduce { m1, m2 -> m1 + m2 }
52-
val api = getBinaryAPI(JarFile(jarFile), visibilities).filterOutNonPublic(nonPublicPackages)
53-
api.dumpAndCompareWith(File("reference-public-api").resolve("$moduleName.txt"))
52+
JarFile(jarPath).use { jarFile ->
53+
val api = getBinaryAPI(jarFile, visibilities).filterOutNonPublic(nonPublicPackages)
54+
api.dumpAndCompareWith(File("reference-public-api").resolve("$moduleName.txt"))
55+
// check for atomicfu leaks
56+
jarFile.checkForAtomicFu()
57+
}
5458
}
5559

5660
private fun getJarPath(libsDir: File): File {
@@ -68,3 +72,25 @@ class PublicApiTest(
6872
error("No single file matching $regex in $libsDir:\n${files.joinToString("\n")}")
6973
}
7074
}
75+
76+
private val ATOMIC_FU_REF = "Lkotlinx/atomicfu/".toByteArray()
77+
78+
private fun JarFile.checkForAtomicFu() {
79+
val foundClasses = mutableListOf<String>()
80+
for (e in entries()) {
81+
if (!e.name.endsWith(".class")) continue
82+
val bytes = getInputStream(e).use { it.readBytes() }
83+
loop@for (i in 0 until bytes.size - ATOMIC_FU_REF.size) {
84+
for (j in 0 until ATOMIC_FU_REF.size) {
85+
if (bytes[i + j] != ATOMIC_FU_REF[j]) continue@loop
86+
}
87+
foundClasses += e.name // report error at the end with all class names
88+
break@loop
89+
}
90+
}
91+
if (foundClasses.isNotEmpty()) {
92+
error("Found references to atomicfu in jar file $name in the following class files: ${
93+
foundClasses.joinToString("") { "\n\t\t" + it }
94+
}")
95+
}
96+
}

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ kotlin_version=1.3.30
55

66
# Dependencies
77
junit_version=4.12
8-
atomicfu_version=0.12.5
8+
atomicfu_version=0.12.7
99
html_version=0.6.8
1010
lincheck_version=2.0
1111
dokka_version=0.9.16-rdev-2-mpp-hacks

0 commit comments

Comments
 (0)