From 98f182594e53e5ae0d3e1acfe4e64bbf6eae12f4 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 24 Apr 2019 17:50:19 -0700 Subject: [PATCH] Fix reflective ctor invocation in FlutterFragment (flutter/engine#8735) Class.newInstance() propagates any exception thrown by the nullary constructor, including a checked exception. This effectively bypasses the compile-time exception checking that would otherwise be performed by the compiler. The Constructor.newInstance method avoids this problem by wrapping any exception thrown by the constructor in a (checked) InvocationTargetException. --- .../io/flutter/embedding/android/FlutterFragment.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java index cf71acf0c2f..e8d2cc60cae 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java @@ -4,6 +4,8 @@ package io.flutter.embedding.android; +import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW; + import android.content.Context; import android.content.Intent; import android.os.Build; @@ -25,8 +27,6 @@ import io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener; import io.flutter.plugin.platform.PlatformPlugin; import io.flutter.view.FlutterMain; -import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW; - /** * {@code Fragment} which displays a Flutter UI that takes up all available {@code Fragment} space. *

@@ -228,7 +228,7 @@ public class FlutterFragment extends Fragment { public T build() { try { @SuppressWarnings("unchecked") - T frag = (T) fragmentClass.newInstance(); + T frag = (T) fragmentClass.getDeclaredConstructor().newInstance(); if (frag == null) { throw new RuntimeException("The FlutterFragment subclass sent in the constructor (" + fragmentClass.getCanonicalName() + ") does not match the expected return type.");