Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] kotlin decompilation error #2355

Open
moroal opened this issue Nov 28, 2024 · 1 comment
Open

[core] kotlin decompilation error #2355

moroal opened this issue Nov 28, 2024 · 1 comment
Labels
bug Core Issues in jadx-core module

Comments

@moroal
Copy link

moroal commented Nov 28, 2024

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 moroal added bug Core Issues in jadx-core module labels Nov 28, 2024
@moroal moroal changed the title [core] kotlin decompilation Error [core] kotlin decompilation error Nov 28, 2024
@leumasme
Copy link

leumasme commented Jan 17, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Core Issues in jadx-core module
Projects
None yet
Development

No branches or pull requests

2 participants