Use of UInt8/Unit16/UInt32 breaks android dex/D8 in Fire 2399

Apologies in advance if its already logged, couldn’t see it.

consoleapplication888.zip (226.4 KB)

See the attached swift/cooper project. This is a distillation of a problem from a real project.

import java.util

class MyClass
{
    var sum1: UInt16 = 0
    var sum2: UInt16 = 0
}


print("The magic happens here.")
  1. Compile the code into a jar
  2. Run the Android D8 dexer over the jar, as it would in an android gradle script:
  3. It fails with an ArrayIndexOfBounds, looking at some type annotation
  4. Happens also with use of other UInt types, and with them as local var as well as properties
  5. Doesn’t happen with signed types
thebeast:Debug jon$ ~/.android-sdk/build-tools/28.0.3/d8 consoleapplication888.jar 

Compilation failed with an internal error.

java.lang.ArrayIndexOutOfBoundsException: 2304

at com.android.tools.r8.org.objectweb.asm.ClassReader.readLabel(ClassReader.java:2355)
at com.android.tools.r8.org.objectweb.asm.ClassReader.createLabel(ClassReader.java:2373)
at com.android.tools.r8.org.objectweb.asm.ClassReader.readTypeAnnotations(ClassReader.java:1782)
at com.android.tools.r8.org.objectweb.asm.ClassReader.readCode(ClassReader.java:1293)
at com.android.tools.r8.org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1126)
at com.android.tools.r8.org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
at com.android.tools.r8.org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
at com.android.tools.r8.graph.JarClassFileReader.read(JarClassFileReader.java:67)
at com.android.tools.r8.dex.ApplicationReader$ClassReader.lambda$readClassSources$1(ApplicationReader.java:231)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
thebeast:Debug jon$

This was on android build tools 28.0.3, Fire 2399

1 Like

Thanks, logged as bugs://82616

d8? Is that something new?

Relatively new. It’s the replacement for dx.jar and is the default dexer now (since Android 28 I think).
https://developer.android.com/studio/command-line/d8
Has in general much better error messages, but not in this case.
I had to hook up the Eclipse debugger up to work out which methods were at fault, then tracked it down to UInt16 vars inside the method.
It’s blowing up in creating it’s model of the class/method before it does the dexing.

1 Like

Seems Local variable annotations aren’t written correctly in some cases. DEX completely ignores this, and so does Java, which is why I never spotted it before. I’ll push a fix for this, thanks for the report.

2 Likes

bugs://82616 got closed with status fixed.

Thanks. Just FYI I later found the same issue with UInt64 as a return type for a method. Although thinking about it that method must have implicit local vars of that type too.

yeah it’s not the result type itself, it’s the implied result variable.

Btw, we (experimentally) support using D8 from the standard build tool chain, set the UseD8 to true.

1 Like