skylot / jadx

Dex to Java decompiler
Apache License 2.0
41.81k stars 4.88k forks source link

[core] Code restructure failed for a small method #1003

Open bagipro opened 4 years ago

bagipro commented 4 years ago

Class androidx.navigation.NavType

    /* JADX DEBUG: Failed to insert an additional move for type inference into block B:0:0x0000 */
    /* JADX DEBUG: Failed to insert an additional move for type inference into block B:3:0x0008 */
    /* JADX DEBUG: Failed to insert an additional move for type inference into block B:6:0x0010 */
    /* JADX DEBUG: Multi-variable search result rejected for r1v0, resolved type: java.lang.String */
    /* JADX DEBUG: Multi-variable search result rejected for r1v3, resolved type: java.lang.String */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r1v1, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r1v2, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r1v6, types: [androidx.navigation.NavType, androidx.navigation.NavType<java.lang.Float>] */
    /* JADX WARN: Type inference failed for: r1v7, types: [androidx.navigation.NavType<java.lang.Long>, androidx.navigation.NavType] */
    /* JADX WARN: Type inference failed for: r1v8, types: [androidx.navigation.NavType, androidx.navigation.NavType<java.lang.Integer>] */
    /* JADX WARNING: Can't wrap try/catch for region: R(3:3|4|5) */
    /* JADX WARNING: Can't wrap try/catch for region: R(3:6|7|8) */
    /* JADX WARNING: Can't wrap try/catch for region: R(3:9|10|11) */
    /* JADX WARNING: Code restructure failed: missing block: B:10:?, code lost:
        androidx.navigation.NavType.BoolType.parseValue(r1);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:11:0x001f, code lost:
        return androidx.navigation.NavType.BoolType;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:14:0x0022, code lost:
        return androidx.navigation.NavType.StringType;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:4:?, code lost:
        androidx.navigation.NavType.LongType.parseValue(r1);
        r1 = androidx.navigation.NavType.LongType;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:5:0x000f, code lost:
        return r1;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:7:?, code lost:
        androidx.navigation.NavType.FloatType.parseValue(r1);
        r1 = androidx.navigation.NavType.FloatType;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:8:0x0017, code lost:
        return r1;
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:3:0x0008 */
    /* JADX WARNING: Missing exception handler attribute for start block: B:6:0x0010 */
    /* JADX WARNING: Missing exception handler attribute for start block: B:9:0x0018 */
    static androidx.navigation.NavType inferFromValue(java.lang.String str) {
        IntType.parseValue(str);
        str = IntType;
        return str;
    }

Actual source: https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/navigation/navigation-common/src/main/java/androidx/navigation/NavType.java#188

    static NavType inferFromValue(@NonNull String value) {
        //because we allow Long literals without the L suffix at runtime,
        //the order of IntType and LongType parsing has to be reversed compared to Safe Args
        try {
            IntType.parseValue(value);
            return IntType;
        } catch (IllegalArgumentException e) {
            //ignored, proceed to check next type
        }
        try {
            LongType.parseValue(value);
            return LongType;
        } catch (IllegalArgumentException e) {
            //ignored, proceed to check next type
        }
        try {
            FloatType.parseValue(value);
            return FloatType;
        } catch (IllegalArgumentException e) {
            //ignored, proceed to check next type
        }
        try {
            BoolType.parseValue(value);
            return BoolType;
        } catch (IllegalArgumentException e) {
            //ignored, proceed to check next type
        }
        return StringType;
    }

APK: https://drive.google.com/file/d/1Hmwjs-Qc8kKc7mx90oC_n1YagOd01jar/view?usp=sharing

bagipro commented 3 years ago

Last comment fixed the problem. Now it's decompiling to

    static androidx.navigation.NavType inferFromValue(java.lang.String str) {
        try {
            IntType.parseValue(str);
            return IntType;
        } catch (java.lang.IllegalArgumentException unused) {
            try {
                LongType.parseValue(str);
                return LongType;
            } catch (java.lang.IllegalArgumentException unused2) {
                try {
                    FloatType.parseValue(str);
                    return FloatType;
                } catch (java.lang.IllegalArgumentException unused3) {
                    try {
                        BoolType.parseValue(str);
                        return BoolType;
                    } catch (java.lang.IllegalArgumentException unused4) {
                        return StringType;
                    }
                }
            }
        }
    }

It would be great if jadx moves all parseValue statements outside catch block