Skip to content

Commit

Permalink
Fix broken systrace marker in getViewManagerNames
Browse files Browse the repository at this point in the history
Summary:
Noticed this marker was not properly ended in the case where an early return happens. The fact that that early return is happening there is problematic too, so added a warning to follow-up on.

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D39271917

fbshipit-source-id: 86dd5b1a46978629584f7cb0d615f2ad99d5a2f8
  • Loading branch information
javache authored and facebook-github-bot committed Sep 8, 2022
1 parent 0526176 commit a888f0c
Showing 1 changed file with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -961,39 +961,43 @@ public List<ViewManager> getOrCreateViewManagers(

public Collection<String> getViewManagerNames() {
Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ReactInstanceManager.getViewManagerNames");
Collection<String> viewManagerNames = mViewManagerNames;
if (viewManagerNames != null) {
return viewManagerNames;
}
ReactApplicationContext context;
synchronized (mReactContextLock) {
context = (ReactApplicationContext) getCurrentReactContext();
if (context == null || !context.hasActiveReactInstance()) {
return Collections.emptyList();
try {
Collection<String> viewManagerNames = mViewManagerNames;
if (viewManagerNames != null) {
return viewManagerNames;
}
ReactApplicationContext context;
synchronized (mReactContextLock) {
context = (ReactApplicationContext) getCurrentReactContext();
if (context == null || !context.hasActiveReactInstance()) {
FLog.w(ReactConstants.TAG, "Calling getViewManagerNames without active context");
return Collections.emptyList();
}
}
}

synchronized (mPackages) {
if (mViewManagerNames == null) {
Set<String> uniqueNames = new HashSet<>();
for (ReactPackage reactPackage : mPackages) {
SystraceMessage.beginSection(
TRACE_TAG_REACT_JAVA_BRIDGE, "ReactInstanceManager.getViewManagerName")
.arg("Package", reactPackage.getClass().getSimpleName())
.flush();
if (reactPackage instanceof ViewManagerOnDemandReactPackage) {
Collection<String> names =
((ViewManagerOnDemandReactPackage) reactPackage).getViewManagerNames(context);
if (names != null) {
uniqueNames.addAll(names);
synchronized (mPackages) {
if (mViewManagerNames == null) {
Set<String> uniqueNames = new HashSet<>();
for (ReactPackage reactPackage : mPackages) {
SystraceMessage.beginSection(
TRACE_TAG_REACT_JAVA_BRIDGE, "ReactInstanceManager.getViewManagerName")
.arg("Package", reactPackage.getClass().getSimpleName())
.flush();
if (reactPackage instanceof ViewManagerOnDemandReactPackage) {
Collection<String> names =
((ViewManagerOnDemandReactPackage) reactPackage).getViewManagerNames(context);
if (names != null) {
uniqueNames.addAll(names);
}
}
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
SystraceMessage.endSection(TRACE_TAG_REACT_JAVA_BRIDGE).flush();
mViewManagerNames = uniqueNames;
}
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
mViewManagerNames = uniqueNames;
return mViewManagerNames;
}
return mViewManagerNames;
} finally {
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
}

Expand Down

0 comments on commit a888f0c

Please sign in to comment.