Skip to content

Commit

Permalink
Handle null connections (#37626)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #37626

`inspector_->connect` can return `null` when the connection fails. Check for `null` and raise an exception (preventing a later crash when the `null` connection is used).

Changelog: [Internal]

Reviewed By: voideanvalue

Differential Revision: D46126080

fbshipit-source-id: 42e08687b4d425dd87642cf6b61f675e77c738ee
  • Loading branch information
Matt Blagden authored and facebook-github-bot committed Jun 6, 2023
1 parent 7fb9e4f commit 3f0caed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public static List<Page> getPages() {

public static LocalConnection connect(int pageId, RemoteConnection remote) {
try {
return instance().connectNative(pageId, remote);
final LocalConnection local = instance().connectNative(pageId, remote);
if (local == null) {
throw new IllegalStateException("Can't open failed connection");
}
return local;
} catch (UnsatisfiedLinkError e) {
FLog.e(ReactConstants.TAG, "Inspector doesn't work in open source yet", e);
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ jni::local_ref<JLocalConnection::javaobject> JInspector::connect(
jni::alias_ref<JRemoteConnection::javaobject> remote) {
auto localConnection = inspector_->connect(
pageId, std::make_unique<RemoteConnection>(std::move(remote)));
return JLocalConnection::newObjectCxxArgs(std::move(localConnection));
return localConnection
? JLocalConnection::newObjectCxxArgs(std::move(localConnection))
: nullptr;
}

void JInspector::registerNatives() {
Expand Down

0 comments on commit 3f0caed

Please sign in to comment.