Skip to content

Commit 2c39bc5

Browse files
authored
[CQ] migrate off deprecated Class.newInstance() invocation (#8376)
Replaces `clazz.newInstance()` with the preferred `clazz.getDeclaredConstructor().newInstance()` and updates exception handling appropriately. Relevant verifier output: ``` #Deprecated method java.lang.Class.newInstance() invocation Deprecated method java.lang.Class.newInstance() : T is invoked in io.flutter.actions.OpenInAndroidStudioAction.actionPerformed(AnActionEvent) : void ``` --- - [x] I’ve reviewed the contributor guide and applied the relevant portions to this PR. <details> <summary>Contribution guidelines:</summary><br> - See our [contributor guide]([https://github.com/dart-lang/sdk/blob/main/CONTRIBUTING.md](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview) for general expectations for PRs. - Larger or significant changes should be discussed in an issue before creating a PR. - Dart contributions to our repos should follow the [Dart style guide](https://dart.dev/guides/language/effective-dart) and use `dart format`. - Java and Kotlin contributions should strive to follow Java and Kotlin best practices ([discussion](#8098)). </details>
1 parent 2b0913d commit 2c39bc5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/io/flutter/actions/OpenInAndroidStudioAction.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.jetbrains.annotations.Nullable;
3333

3434
import java.io.File;
35+
import java.lang.reflect.InvocationTargetException;
3536

3637
/**
3738
* This action has been removed from the plugin.xml as a required dependent method call {GradleProjectImporter.importAndOpenProjectCore()
@@ -63,10 +64,11 @@ public void actionPerformed(@NotNull final AnActionEvent event) {
6364
//noinspection unchecked
6465
final Class<OpenInAndroidStudioAction> opener =
6566
(Class<OpenInAndroidStudioAction>)Class.forName("io.flutter.actions.OpenAndroidModule");
66-
opener.newInstance().actionPerformed(event);
67+
opener.getDeclaredConstructor().newInstance().actionPerformed(event);
6768
return;
6869
}
69-
catch (ClassNotFoundException | IllegalAccessException | InstantiationException ignored) {
70+
catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException |
71+
InvocationTargetException ignored) {
7072
}
7173
}
7274

0 commit comments

Comments
 (0)