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

Fields are not initialized after setContentView [core] #1599

Closed
redmi111 opened this issue Aug 2, 2022 · 6 comments
Closed

Fields are not initialized after setContentView [core] #1599

redmi111 opened this issue Aug 2, 2022 · 6 comments
Labels
bug Core Issues in jadx-core module
Milestone

Comments

@redmi111
Copy link

redmi111 commented Aug 2, 2022

Fields on the image are supposed to be initialized after setContentView because right now in this way objects are null since they're not initialized properly.

v1.4.3
image

P.S: Those are global variable and not inside onCreate method and that's the problem (trying to initialize in the field declaration itself)

@redmi111 redmi111 added bug Core Issues in jadx-core module labels Aug 2, 2022
@skylot
Copy link
Owner

skylot commented Aug 3, 2022

@redmi111 can you share a sample for this issue? Also share class which contains this code. Without this, it is hard to understand the issue.

@redmi111
Copy link
Author

redmi111 commented Aug 4, 2022

https://we.tl/t-ksKXl4VSeS

Here is the APK and you can find this inside ExitDialog class

@jpstotz
Copy link
Collaborator

jpstotz commented Aug 4, 2022

@redmi111 If you look at the smali code then you will see that the decompiled code is correct, they are initialized in <init>(Landroid/content/Context;)V. So if the code is incorrect this is a bug created by the author of the app. Jadx can only decompile what is present, no matter if it is correct Android code or not.

@redmi111
Copy link
Author

redmi111 commented Aug 4, 2022

Understood, Thanks for the clarification.

@jpstotz jpstotz closed this as completed Aug 4, 2022
@skylot
Copy link
Owner

skylot commented Aug 4, 2022

As I understand @redmi111 point to the incorrect initialization order and indeed this is an issue here.
I prepare a simple test case:

	StringBuilder sb;
	int field;

	public TestCls() {
		initBuilder(new StringBuilder("sb"));
		this.field = initField();
		this.sb.append(this.field);
	}

	private void initBuilder(StringBuilder sb) {
		this.sb = sb;
	}

	private int initField() {
		return sb.length();
	}

Decompiled code:

    int field = initField();
    StringBuilder sb;

    public TestCls() {
        initBuilder(new StringBuilder("sb"));
        this.sb.append(this.field);
    }
...

Decompiled code throw NPE from initField method because it called before initBuilder.

@skylot skylot reopened this Aug 4, 2022
@skylot skylot added this to the TBD milestone Aug 4, 2022
@skylot
Copy link
Owner

skylot commented Aug 4, 2022

Fixed.

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

3 participants