ran into a weird bug using table testing. an arra...
# kotlintest
b
ran into a weird bug using table testing. an array out of bounds in SignatureParser, of all things...when i run the test outside of a table test it seems to work. i'll start a thread and post details.
the method under test is
Copy code
fun ByteArray.getLong(byteIndex: Int): Long {
    val b1 = get(byteIndex + 0)
    val b2 = get(byteIndex + 1)
    val b3 = get(byteIndex + 2)
    val b4 = get(byteIndex + 3)
    val b5 = get(byteIndex + 4)
    val b6 = get(byteIndex + 5)
    val b7 = get(byteIndex + 6)
    val b8 = get(byteIndex + 7)

    return ((b1.toLong() and 0xFF) shl 56) or
           ((b2.toLong() and 0xFF) shl 48) or
           ((b3.toLong() and 0xFF) shl 40) or
           ((b4.toLong() and 0xFF) shl 32) or
           ((b5.toLong() and 0xFF) shl 24) or
           ((b6.toLong() and 0xFF) shl 16) or
           ((b7.toLong() and 0xFF) shl 8) or
           ((b8.toLong() and 0xFF))
}
the test is
Copy code
class ByteArrayExtensionsKtTest : ShouldSpec() {
    init {
        "ByteArray.getLong/putLong" {
            should("parse the Long correctly") {
//                forall(
//                    row(byteArrayOf(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), 0.toLong()),
//                    row(byteArrayOf(0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF), 9223372036854775807L)
//                ) { buf, expectedLong ->
//                    buf.getLong(0) shouldBe expectedLong
//
//                    val array = ByteArray(4)
//                    array.putLong(0, expectedLong)
//                    array should haveSameContentAs(buf)
//                }
                    byteArrayOf(0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF).getLong(0) shouldBe 9223372036854775807L
            }
        }
    }
where
byteArrayOf
is defined as
Copy code
fun byteArrayOf(vararg elements: Number): ByteArray {
    return elements.map { it.toByte() }.toByteArray()
}
the part currently uncommented (in the test) works
if i comment that out and run the other part, i get array out of bounds with some deep stack
Copy code
current:95, SignatureParser (sun.reflect.generics.parser)
parseSuperInterfaces:559, SignatureParser (sun.reflect.generics.parser)
parseClassSignature:214, SignatureParser (sun.reflect.generics.parser)
parseClassSig:156, SignatureParser (sun.reflect.generics.parser)
parse:57, ClassRepository (sun.reflect.generics.repository)
parse:41, ClassRepository (sun.reflect.generics.repository)
<init>:74, AbstractRepository (sun.reflect.generics.repository)
<init>:49, GenericDeclRepository (sun.reflect.generics.repository)
<init>:53, ClassRepository (sun.reflect.generics.repository)
make:70, ClassRepository (sun.reflect.generics.repository)
<clinit>:43, ClassRepository (sun.reflect.generics.repository)
getGenericInfo:2548, Class (java.lang)
getGenericInterfaces:912, Class (java.lang)
renderLambdaToString:41, ReflectionFactory (kotlin.jvm.internal)
renderLambdaToString:74, Reflection (kotlin.jvm.internal)
toString:163, SuspendLambda (kotlin.coroutines.jvm.internal)
valueOf:2994, String (java.lang)
append:131, StringBuilder (java.lang)
toString:-1, TestCase (io.kotlintest)
valueOf:2994, String (java.lang)
append:131, StringBuilder (java.lang)
toString:-1, TopLevelTest (io.kotlintest.extensions)
valueOf:2994, String (java.lang)
append:131, StringBuilder (java.lang)
toString:462, AbstractCollection (java.util)
valueOf:2994, String (java.lang)
append:131, StringBuilder (java.lang)
toString:-1, TopLevelTests (io.kotlintest.extensions)
valueOf:2994, String (java.lang)
append:131, StringBuilder (java.lang)
invoke:43, SpecExecutor$execute$$inlined$invoke$lambda$1 (io.kotlintest.runner.jvm.spec)
invoke:17, SpecExecutor$execute$$inlined$invoke$lambda$1 (io.kotlintest.runner.jvm.spec)
withExecutor:28, SpecExecutor (io.kotlintest.runner.jvm.spec)
execute:34, SpecExecutor (io.kotlintest.runner.jvm.spec)
run:102, TestEngine$submitSpec$1 (io.kotlintest.runner.jvm)
call:511, Executors$RunnableAdapter (java.util.concurrent)
run$$$capture:266, FutureTask (java.util.concurrent)
run:-1, FutureTask (java.util.concurrent)
 - Async stack trace
<init>:151, FutureTask (java.util.concurrent)
newTaskFor:87, AbstractExecutorService (java.util.concurrent)
submit:111, AbstractExecutorService (java.util.concurrent)
submitSpec:90, TestEngine (io.kotlintest.runner.jvm)
submitAll:48, TestEngine (io.kotlintest.runner.jvm)
execute:75, TestEngine (io.kotlintest.runner.jvm)
execute:44, KotlinTestEngine (io.kotlintest.runner.junit5)
execute:229, DefaultLauncher (org.junit.platform.launcher.core)
lambda$execute$6:197, DefaultLauncher (org.junit.platform.launcher.core)
withInterceptedStreams:211, DefaultLauncher (org.junit.platform.launcher.core)
execute:191, DefaultLauncher (org.junit.platform.launcher.core)
execute:128, DefaultLauncher (org.junit.platform.launcher.core)
startRunnerWithArgs:74, JUnit5IdeaTestRunner (com.intellij.junit5)
startRunnerWithArgs:47, IdeaTestRunner$Repeater (com.intellij.rt.execution.junit)
prepareStreamsAndStart:242, JUnitStarter (com.intellij.rt.execution.junit)
main:70, JUnitStarter (com.intellij.rt.execution.junit)
s
The integer literal does not conform to the expected type Byte
b
oh, why is it expecting byte?
you mean in
row
?
s
in byteArrayOf(0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF).getLong(0) shouldBe 9223372036854775807L
b
ah shit, i see it
i had a copy paste error
only allocated 4 bytes in the array below that
val array = ByteArray(4)
s
ok so false alarm
b
very confusing stack for that
my bad
s
np
something in the code that generates a stack for the lamba
might be worth raising a bug against kotlin
that seems to be where the issue is