Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

@OnActivityResult(REQUEST_CODE) creates fall-through switch-case-statements #427

@ironjan

Description

@ironjan

Using multiple @OnActivityResult(REQUEST_CODE) causes AndroidAnnotation to create switch-case-statements that can enter the wrong case by falling through.

AndroidAnnotation should create this switch-case-statements with "break;" after every case.

Example:

@OnActivityResult(CHOOSE_REQUEST_CODE)
void resultChooseExisting(int resultCode, Intent data) {...}

@OnActivityResult(TAKE_REQUEST_CODE)
void resultTakePhoto(int resultCode) {...}

generates

 @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        StreamActivity_.super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case  1 :
                StreamActivity_.this.resultTakePhoto(resultCode);
            case  0 :
                StreamActivity_.this.resultChooseExisting(resultCode, data);
        }
    }

with the warning "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above" on the second case (0).

Code that should be generated instead:

 @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        StreamActivity_.super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case  1 :
                StreamActivity_.this.resultTakePhoto(resultCode);
                break;
            case  0 :
                StreamActivity_.this.resultChooseExisting(resultCode, data);
                break;
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions