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

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;
        }
    }

Activity

  1. mathieuboniface commented on Dec 8, 2012

    @mathieuboniface
    Contributor

    Hi ironjan,

    You're definitely right and this bug seems to be a major one. Thank you for reporting this !

    I've provided a fix on #428. As you can see on the CI platform, it has been integrated into the latest snapshot.

    By using this snapshot you should see the break statement appear on the end of each case statement, like you said.

    Please reopen this issue if you are still facing this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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