jadx icon indicating copy to clipboard operation
jadx copied to clipboard

[core] kotlin decompilation error

Open moroal opened this issue 1 year ago • 1 comments

Issue details

kotlin code

package com.test

internal object MyLog {

    enum class LogType {
        a,
        b,
        c,
    }

    private fun i(tag: String, msg: String) {

    }

    @JvmStatic
    fun log1(tag: String, taskName: String) {
        i(tag, "s $taskName")
    }

    @JvmStatic
    fun log2(tag: String, taskName: String, type: LogType, cost: Long) {
        i(tag, "r $taskName c $cost t $type")
    }
}

decompile:

package com.test;

import kotlin.Metadata;
import kotlin.jvm.JvmStatic;
import kotlin.jvm.internal.Intrinsics;
import org.jetbrains.annotations.NotNull;

public final class MyLog {

    @NotNull
    public static final MyLog INSTANCE = new MyLog();

    private MyLog() {
    }

    private final void i(String tag, String msg) {
    }

    @JvmStatic
    public static final void log1(@NotNull String tag, @NotNull String taskName) {
        Intrinsics.checkNotNullParameter(tag, "tag");
        Intrinsics.checkNotNullParameter(taskName, "taskName");
        INSTANCE.i(tag, "s " + taskName);
    }

    @JvmStatic
    public static final void log2(@NotNull String tag, @NotNull String taskName, @NotNull MyLog$LogType type, long cost) {
        Intrinsics.checkNotNullParameter(tag, "tag");
        Intrinsics.checkNotNullParameter(taskName, "taskName");
        Intrinsics.checkNotNullParameter(type, "type");
        MyLog myLog = INSTANCE;
        myLog.i(tag, "r " + taskName + " c " + cost + " t " + myLog);
    }
}

expectation(log2):

myLog.i(tag, "r " + taskName + " c " + cost + " t " + type);

actual result:

MyLog myLog = INSTANCE;
myLog.i(tag, "r " + taskName + " c " + cost + " t " + myLog);

env:

kotlinOptions.jvmTarget = "11" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22" agp:8.1.4

Relevant log output or stacktrace

No response

Provide sample and class/method full name

No response

Jadx version

1.5.1

moroal avatar Nov 28 '24 06:11 moroal

Jadx decompiles to java, not to kotlin. Java has nothing like kotlin object. Internally, they are compiled as a java singleton by storing a single instance on a static member called INSTANCE, as you see here. (This is familiar to anyone who has had to use kotlin objects from java before. If you called this from a java class, you'd also have to write MyLog.INSTANCE.i(...) )

The decompilation output is correct, there is no error. Or what do you mean?

leumasme avatar Jan 17 '25 13:01 leumasme