Fix potential NPE in Layout Inspector
Summary: Fixed NPE linked by task. From the code, that stuff should never be null, unless there is some threading / concurrency issue, which there apparently is. In that case, failing with a warning is imho a bit more elegant than raising exceptions from a debugging tool Reviewed By: lblasa Differential Revision: D32278044 fbshipit-source-id: 710fcdcfe458f33bbb806d9f2f1b9352252eedec
This commit is contained in:
committed by
Facebook GitHub Bot
parent
cd58ef96a2
commit
750f26eaa3
@@ -592,7 +592,11 @@ public class InspectorFlipperPlugin implements FlipperPlugin {
|
|||||||
@Override
|
@Override
|
||||||
protected void runOrThrow() throws Exception {
|
protected void runOrThrow() throws Exception {
|
||||||
for (int i = 0, count = descriptor.getChildCount(obj); i < count; i++) {
|
for (int i = 0, count = descriptor.getChildCount(obj); i < count; i++) {
|
||||||
final Object child = assertNotNull(descriptor.getChildAt(obj, i));
|
final Object child = descriptor.getChildAt(obj, i);
|
||||||
|
if (child == null) {
|
||||||
|
Log.w(TAG, "Failed to get child at index: " + i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
children.put(trackObject(child));
|
children.put(trackObject(child));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
package com.facebook.flipper.plugins.inspector;
|
package com.facebook.flipper.plugins.inspector;
|
||||||
|
|
||||||
import static com.facebook.flipper.plugins.inspector.ThrowableMessageMatcher.hasThrowableWithMessage;
|
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.hamcrest.CoreMatchers.hasItem;
|
import static org.hamcrest.CoreMatchers.hasItem;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
@@ -31,7 +30,6 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.hamcrest.CoreMatchers;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -325,7 +323,7 @@ public class InspectorFlipperPluginTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullChildThrows() throws Exception {
|
public void testNullChildNotThrows() throws Exception {
|
||||||
final InspectorFlipperPlugin plugin =
|
final InspectorFlipperPlugin plugin =
|
||||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, null);
|
new InspectorFlipperPlugin(mApp, mDescriptorMapping, null);
|
||||||
final FlipperResponderMock responder = new FlipperResponderMock();
|
final FlipperResponderMock responder = new FlipperResponderMock();
|
||||||
@@ -344,11 +342,7 @@ public class InspectorFlipperPluginTest {
|
|||||||
new FlipperObject.Builder().put("ids", new FlipperArray.Builder().put("test")).build(),
|
new FlipperObject.Builder().put("ids", new FlipperArray.Builder().put("test")).build(),
|
||||||
responder);
|
responder);
|
||||||
|
|
||||||
assertThat(connection.errors.size(), equalTo(1));
|
assertThat(connection.errors.size(), equalTo(0));
|
||||||
assertThat(
|
|
||||||
connection.errors,
|
|
||||||
CoreMatchers.hasItem(
|
|
||||||
hasThrowableWithMessage("java.lang.RuntimeException: Unexpected null value")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestNode {
|
private class TestNode {
|
||||||
|
|||||||
Reference in New Issue
Block a user