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

Avoid generate @Delegate method body NPE #3811

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eeoun
Copy link

@eeoun eeoun commented Jan 17, 2025

Avoid generate @DeleGate method body NPE when deletegate target is null on javac's HandleDelegate

Add a null check before delegate call,now is only for javac

before:

    @Generated
    public void asd() {
        this.getSd().asd();
    }

    @Generated
    public String getExt() {
        return this.getSd().getExt();
    }

    @Generated
    public void setExt(final String ext) {
        this.getSd().setExt(ext);
    }

after

    @Generated
    public void asd() {
        if (this.getSd() != null) {
            this.getSd().asd();
        }
    }

    @Generated
    public String getExt() {
        return this.getSd() == null ? null : this.getSd().getExt();
    }

    @Generated
    public void setExt(final String ext) {
        if (this.getSd() != null) {
            this.getSd().setExt(ext);
        }
    }

@eeoun
Copy link
Author

eeoun commented Jan 17, 2025

There is also e ecj's implement version. But i've not ever test event compile it. But I think it's ok. I'll add in PR if you think is ok.

commit 4d4e70b8c4b570740dac35cd45d2ef5aab821eeb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant