Skip to content

java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.editing.TextInputPlugin.onProvideAutofillVirtualStructure(android.view.ViewStructure, int)' on a null object reference #180383

@LailaiMaster

Description

@LailaiMaster

Steps to reproduce

I'd like to file an issue for Flutter. Similar to #149792, but that issue was closed without being resolved, and this problem occurs in the latest version. I’ll add some additional details.

In https://github.com/flutter/flutter/blob/master/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java, the following code block:

if (host.attachToEngineAutomatically()) {
  Log.v(TAG, "Attaching FlutterEngine to FlutterView.");
  flutterView.attachToFlutterEngine(flutterEngine);
}

allows FlutterView to be configured to not attach to the engine automatically, which is a useful feature that enables users to attach it later when needed. However, this leads to an issue: when the FlutterFragment lifecycle reaches onCreateView, and host.attachToEngineAutomatically() returns false, flutterView.attachToFlutterEngine(flutterEngine) is not executed. Meanwhile, the textInputPlugin in FlutterView is initialized in attachToFlutterEngine. If attachToFlutterEngine is not executed, but the method

@Override
public void onProvideAutofillVirtualStructure(@NonNull ViewStructure structure, int flags) {
  super.onProvideAutofillVirtualStructure(structure, flags);
  textInputPlugin.onProvideAutofillVirtualStructure(structure, flags);
}

is invoked, it will eventually cause a null pointer exception due to textInputPlugin being uninitialized.

My suggestion is to add a null check for textInputPlugin to prevent this issue.

Expected results

App crashed.

Actual results

App crashed.

Code sample

no

Screenshots or Video

No response

Logs

Flutter Doctor output

no

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsc: crashStack traces logged to the consoleengineflutter/engine related. See also e: labels.platform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions