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

Fixing bug when ListenableEditingState is provided initialState with a valid composing range, android.view.inputmethod.BaseInputConnection.setComposingRegion(int, int) has NPE #30916

Merged
merged 4 commits into from Jan 20, 2022

Conversation

fzyzcjy
Copy link
Contributor

@fzyzcjy fzyzcjy commented Jan 19, 2022

Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.
See flutter/flutter#96570

List which issues are fixed by this PR. You must list at least one issue.
Fix flutter/flutter#96570

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on
    writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard
Copy link

This pull request was opened against a branch other than main. Since Flutter pull requests should not normally be opened against branches other than main, I have changed the base to main. If this was intended, you may modify the base back to master. See the Release Process for information about how other branches get updated.

Reviewers: Use caution before merging pull requests to branches other than main, unless this is an intentional hotfix/cherrypick.

@flutter-dashboard flutter-dashboard bot changed the base branch from master to main January 19, 2022 00:10
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

1 similar comment
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Jan 19, 2022

Well cannot understand that CI error... Have searched keyword ListenableEditingState but no related things. The log seems also unrelated to my code change... Could anyone plz give some hints?

Possibly related @chinmaygarde @darshankawar

@jason-simmons
Copy link
Member

The "Linux Unopt" CI error is asking for a change to the code formatting
(see https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8824653695614065553/+/u/test:_format_and_dart_test/stdout)

The "build_and_test_linux_unopt_debug" CI error is a flaky test that has been seen before (see flutter/flutter#95751)

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Jan 19, 2022

@jason-simmons thanks! done

@@ -141,7 +141,11 @@ public void setComposingRange(int composingStart, int composingEnd) {
if (composingStart < 0 || composingStart >= composingEnd) {
BaseInputConnection.removeComposingSpans(this);
} else {
mDummyConnection.setComposingRegion(composingStart, composingEnd);
if (mDummyConnection != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make more sense to move the mDummyConnection initialization to before the setEditingState call in the constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure. Notice mDummyConnection is init as:

    Editable self = this;
    mDummyConnection =
        new BaseInputConnection(view, true) {
          @Override
          public Editable getEditable() {
            return self;
          }
        };

Where there is a self (indeed this). If we move it at the beginning of constructor, that getEditable can return a not-fully-initialized instance imho

Copy link
Contributor

Choose a reason for hiding this comment

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

If I recall correctly the dummy connection is a quirk to get access to the BaseInputConnection.setComposingRegion static method:
https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/view/inputmethod/BaseInputConnection.java;l=104-128;drc=master?q=BaseInputConnection

Since it's called after the super implementation, and all the dummy connection does is changing the current composing region, it should be fine to return the Editable I think (feel free to add a code comment there).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for fixing this!

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Jan 20, 2022

You are welcome!

@chinmaygarde chinmaygarde added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jan 20, 2022
@fluttergithubbot fluttergithubbot merged commit d405b2b into flutter:main Jan 20, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 21, 2022
…State` with a valid composing range, `android.view.inputmethod.BaseInputConnection.setComposingRegion(int, int)` has NPE (flutter/engine#30916)
@kobi666
Copy link

kobi666 commented Jan 21, 2022

@chinmaygarde
yo,
so when can we expect this fix to reach stable?

is there an HF version?

@FabioPaganoAPSystem
Copy link

In flutter version "2.10.0-stable" the bug seems not resolved, I've tested with my app.

@everskies
Copy link

everskies commented Mar 28, 2022

Would be great if this could be merged into stable! This is our most occurring issue at the moment

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Mar 28, 2022

Given my understanding of flutter, seems that we need to wait until next stable (which is roughly 2 months later, unfortunately) if it is not in 2.10. Or, we may make a cherry-pick request

@apoleo88
Copy link

Still get the error with:

Flutter 2.10.4 • channel stable 
Tools • Dart 2.16.2 • DevTools 2.9.2

Specifically when I double-tap to select the text in a text field.

@gonzalonm
Copy link

Looks like this fix has not been included in stable channel yet. Does anybody know where it was included?

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Aug 5, 2022

@gonzalonm May I know where you see it not in stable? from the release date it should have been stable

@gonzalonm
Copy link

I didn't see it in the release notes. Anyways, I could not reproduce the issue with version 3.0.0, so in that version it has been fixed.
Thanks!

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Aug 5, 2022

It may be in release notes of engine, while flutter/flutter repo (not flutter/engine) will not say this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs tests platform-android waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
10 participants