Skip to content

Commit d405b2b

Browse files
authored
Fixing bug when ListenableEditingState is provided initialState with a valid composing range, android.view.inputmethod.BaseInputConnection.setComposingRegion(int, int) has NPE (flutter#30916)
1 parent ed3704c commit d405b2b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

shell/platform/android/io/flutter/plugin/editing/ListenableEditingState.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ void didChangeEditingState(
6060
public ListenableEditingState(
6161
@Nullable TextInputChannel.TextEditState initialState, @NonNull View view) {
6262
super();
63-
if (initialState != null) {
64-
setEditingState(initialState);
65-
}
6663

6764
Editable self = this;
6865
mDummyConnection =
@@ -72,6 +69,10 @@ public Editable getEditable() {
7269
return self;
7370
}
7471
};
72+
73+
if (initialState != null) {
74+
setEditingState(initialState);
75+
}
7576
}
7677

7778
public ArrayList<TextEditingDelta> extractBatchTextEditingDeltas() {

shell/platform/android/test/io/flutter/plugin/editing/ListenableEditingStateTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ public void setUp() {
4242
MockitoAnnotations.openMocks(this);
4343
}
4444

45+
@Test
46+
public void testConstructor() {
47+
// When provided valid composing range, should not fail
48+
new ListenableEditingState(
49+
new TextInputChannel.TextEditState("hello", 1, 4, 1, 4),
50+
new View(RuntimeEnvironment.application));
51+
}
52+
4553
// -------- Start: Test BatchEditing -------
4654
@Test
4755
public void testBatchEditing() {

0 commit comments

Comments
 (0)