Skip to content

IDE-307 Fix failure in quarantined test suite#5143

Open
Kale2605 wants to merge 1 commit intoCatrobat:developfrom
Kale2605:IDE-307
Open

IDE-307 Fix failure in quarantined test suite#5143
Kale2605 wants to merge 1 commit intoCatrobat:developfrom
Kale2605:IDE-307

Conversation

@Kale2605
Copy link
Copy Markdown
Contributor

@Kale2605 Kale2605 commented Jan 26, 2026

getActivity() sometimes null... not yet attached. Fix by wait and try again.

https://catrobat.atlassian.net/browse/IDE-307?atlOrigin=eyJpIjoiNjk3NDllZDk2YmUyNDk2NmFjM2NkYjkwNjRhYzFhNGYiLCJwIjoiaiJ9

Your checklist for this pull request

Please review the contributing guidelines and wiki pages of this repository.

  • Include the name of the Jira ticket in the PR’s title
  • Include a summary of the changes plus the relevant context
  • Choose the proper base branch (develop)
  • Confirm that the changes follow the project’s coding guidelines
  • Verify that the changes generate no compiler or linter warnings
  • Perform a self-review of the changes
  • Verify to commit no other files than the intentionally changed ones
  • Include reasonable and readable tests verifying the added or changed behavior
  • Confirm that new and existing unit tests pass locally
  • Check that the commits’ message style matches the project’s guideline
  • Stick to the project’s gitflow workflow
  • Verify that your changes do not have any conflicts with the base branch
  • After the PR, verify that all CI checks have passed
  • Post a message in the catroid-stage or catroid-ide Slack channel and ask for a code reviewer

@Kale2605 Kale2605 marked this pull request as ready for review January 26, 2026 08:27
Copy link
Copy Markdown
Contributor

@Frajhamster Frajhamster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, except that on SonarQube your code introduced a new issue, which still passes the QualityGate check, so you can decide to take a look at it and try to fix it, or leave it like it is now, up to you.

@Kale2605
Copy link
Copy Markdown
Contributor Author

Looks good, except that on SonarQube your code introduced a new issue, which still passes the QualityGate check, so you can decide to take a look at it and try to fix it, or leave it like it is now, up to you.

Done

getActivity() sometimes null... not yet attached. Fix by wait and try again. And fix code smell.
@sonarqubecloud
Copy link
Copy Markdown

@Kale2605 Kale2605 changed the title IDE 307 Fix failure in quarantined test suite IDE-307 Fix failure in quarantined test suite Jan 27, 2026
@ratschillerp ratschillerp added the Active Member Tickets that are assigned to members that are still currently active label Jan 29, 2026
@dorianpercic dorianpercic self-requested a review January 29, 2026 21:53
Copy link
Copy Markdown
Member

@harshsomankar123-tech harshsomankar123-tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hii @Kale2605 Thanks For the PR
I have found some problems with this implementation:

  1. Infinite retry risk
    If getActivity() keeps returning null, this ends up reposting to the main thread without any real stopping condition. That can quietly pile up work on the UI thread. It would be safer to cap the number of retries or introduce a clear exit path.

  2. Hardcoded false
    onHiddenChanged already gives us the correct hidden value from the system. Passing false ignores that and can lead to the wrong behavior for example, running “show” logic even when the fragment is actually being hidden. We should just forward the original hidden value.

  3. Retry counter not reset
    The retry counter needs to be reset after both success and failure. Otherwise, it can carry over into future hide/show cycles on the same fragment instance and cause inconsistent behavior.

U can refer This snippet:

// Add these fields to the class
private int retryCount = 0;
private static final int MAX_RETRIES = 5;

// Add this helper method
private void retryOnHiddenChanged(final boolean hidden) {
    if (retryCount >= MAX_RETRIES) {
        retryCount = 0; // Reset so future calls can attempt again
        Log.e(TAG, "Failed to update UI in onHiddenChanged after " + MAX_RETRIES + " retries.");
        return;
    }
    retryCount++;
    new Handler(Looper.getMainLooper()).post(() -> {
        if (isAdded()) {
            onHiddenChanged(hidden);
        }
    });
}

// Update the existing onHiddenChanged method
@Override
public void onHiddenChanged(boolean hidden) {
    if (hidden) {
        return; // UI update logic is only needed when becoming visible
    }

    if (getActivity() == null) {
        retryOnHiddenChanged(hidden);
        return;
    }

    retryCount = 0; // Reset count on success
    
    ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
    boolean isRestoringPreviouslyDestroyedActivity = actionBar == null;
    
    if (!isRestoringPreviouslyDestroyedActivity) {
        actionBar.setTitle(R.string.formula_editor_title);
        BottomBar.hideBottomBar(getActivity());
        updateButtonsOnKeyboardAndInvalidateOptionsMenu();
        updateBrickView();
    }
    
    if (chosenCategoryItem != null) {
        addResourceToActiveFormula(chosenCategoryItem.getNameResId());
        chosenCategoryItem = null;
    }
    
    if (chosenUserDataItem != null) {
        if (chosenUserDataItem instanceof UserVariable) {
            addUserVariableToActiveFormula(chosenUserDataItem.getName());
        } else if (chosenUserDataItem instanceof UserList) {
            addUserListToActiveFormula(chosenUserDataItem.getName());
        } else if (chosenUserDataItem instanceof UserDefinedBrickInput) {
            addUserDefinedBrickInputToActiveFormula(chosenUserDataItem.getName());
        }
        chosenUserDataItem = null;
    }
}

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

Labels

Active Member Tickets that are assigned to members that are still currently active

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants