Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Nullsafe FIXMEs for xplat/js/react-native-github/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/CxxInspectorPackagerConnection.java #50061

Closed
wants to merge 9 commits into from
Closed
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ private static native HybridData initHybrid(

public native void closeQuietly();

// NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
public native void sendEventToAllConnections(String event);

/** Java wrapper around a C++ IWebSocketDelegate, allowing us to call the interface from Java. */
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
@@ -59,6 +60,7 @@
* <li>Genymotion emulator with default settings: 10.0.3.2
* </ul>
*/
@Nullsafe(Nullsafe.Mode.LOCAL)
public class DevServerHelper {
private static final int HTTP_CONNECT_TIMEOUT_MS = 5000;

@@ -205,10 +207,13 @@ public void openInspectorConnection() {
protected Void doInBackground(Void... params) {
Map<String, String> metadata =
AndroidInfoHelpers.getInspectorHostMetadata(mApplicationContext);

String deviceName = metadata.get("deviceName");
if (deviceName == null) {
FLog.w(ReactConstants.TAG, "Could not get device name from Inspector Host Metadata.");
return null;
}
mInspectorPackagerConnection =
new CxxInspectorPackagerConnection(
getInspectorDeviceUrl(), metadata.get("deviceName"), mPackageName);
new CxxInspectorPackagerConnection(getInspectorDeviceUrl(), deviceName, mPackageName);
mInspectorPackagerConnection.connect();
return null;
}
@@ -447,7 +452,7 @@ public String getSourceUrl(String mainModuleName) {
final Request request = new Request.Builder().url(resourceURL).build();

try (Response response = mClient.newCall(request).execute()) {
if (!response.isSuccessful()) {
if (!response.isSuccessful() || response.body() == null) {
return null;
}

Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.common.JavascriptException;
import com.facebook.react.common.annotations.VisibleForTesting;
import java.io.IOException;
@@ -29,6 +30,7 @@
import okhttp3.WebSocketListener;

/** A wrapper around WebSocketClient that recognizes RN debugging message format. */
@Nullsafe(Nullsafe.Mode.LOCAL)
class JSDebuggerWebSocketClient extends WebSocketListener {

private static final String TAG = "JSDebuggerWebSocketClient";
@@ -210,7 +212,7 @@ public void onMessage(@Nullable WebSocket webSocket, String text) {
}

@Override
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
public void onFailure(@Nullable WebSocket webSocket, Throwable t, @Nullable Response response) {
abort("Websocket exception", t);
}

Original file line number Diff line number Diff line change
@@ -7,14 +7,17 @@

package com.facebook.react.devsupport;

import com.facebook.infer.annotation.Nullsafe;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import okio.Buffer;
import okio.BufferedSource;
import okio.ByteString;

/** Utility class to parse the body of a response of type multipart/mixed. */
@Nullsafe(Nullsafe.Mode.LOCAL)
class MultipartStreamReader {
// Standard line separator for HTTP.
private static final String CRLF = "\r\n";
@@ -60,7 +63,7 @@ private void emitChunk(Buffer chunk, boolean done, ChunkListener listener) throw
ByteString marker = ByteString.encodeUtf8(CRLF + CRLF);
long indexOfMarker = chunk.indexOf(marker);
if (indexOfMarker == -1) {
listener.onChunkComplete(null, chunk, done);
listener.onChunkComplete(Collections.emptyMap(), chunk, done);
} else {
Buffer headers = new Buffer();
Buffer body = new Buffer();
@@ -148,6 +151,7 @@ public boolean readAllParts(ChunkListener listener) throws IOException {
Buffer chunk = new Buffer();
content.skip(chunkStart);
content.read(chunk, length);
// NULLSAFE_FIXME[Parameter Not Nullable]
emitProgress(currentHeaders, chunk.size() - currentHeadersLength, true, listener);
emitChunk(chunk, isCloseDelimiter, listener);
currentHeaders = null;
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@
package com.facebook.react.devsupport;

import androidx.annotation.Nullable;
import com.facebook.infer.annotation.Assertions;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.bridge.JavaOnlyArray;
import com.facebook.react.bridge.JavaOnlyMap;
import com.facebook.react.bridge.ReadableArray;
@@ -26,6 +28,7 @@
import org.json.JSONObject;

/** Helper class converting JS and Java stack traces into arrays of {@link StackFrame} objects. */
@Nullsafe(Nullsafe.Mode.LOCAL)
public class StackTraceHelper {

public static final String COLUMN_KEY = "column";
@@ -49,27 +52,29 @@ public class StackTraceHelper {

/** Represents a generic entry in a stack trace, be it originally from JS or Java. */
public static class StackFrameImpl implements StackFrame {
private final String mFile;
@Nullable private final String mFile;
private final String mMethod;
private final int mLine;
private final int mColumn;
private final String mFileName;
@Nullable private final String mFileName;
private final boolean mIsCollapsed;

private StackFrameImpl(String file, String method, int line, int column, boolean isCollapsed) {
private StackFrameImpl(
@Nullable String file, String method, int line, int column, boolean isCollapsed) {
mFile = file;
mMethod = method;
mLine = line;
mColumn = column;
mFileName = file != null ? new File(file).getName() : "";
mFileName = file != null ? new File(file).getName() : null;
mIsCollapsed = isCollapsed;
}

private StackFrameImpl(String file, String method, int line, int column) {
private StackFrameImpl(@Nullable String file, String method, int line, int column) {
this(file, method, line, column, false);
}

private StackFrameImpl(String file, String fileName, String method, int line, int column) {
private StackFrameImpl(
@Nullable String file, @Nullable String fileName, String method, int line, int column) {
mFile = file;
mFileName = fileName;
mMethod = method;
@@ -84,7 +89,8 @@ private StackFrameImpl(String file, String fileName, String method, int line, in
* <p>JS traces return the full path to the file here, while Java traces only return the file
* name (the path is not known).
*/
public String getFile() {
@Override
public @Nullable String getFile() {
return mFile;
}

@@ -109,7 +115,8 @@ public int getColumn() {
* <p>For JS traces this is different from {@link #getFile()} in that it only returns the file
* name, not the full path. For Java traces there is no difference.
*/
public String getFileName() {
@Override
public @Nullable String getFileName() {
return mFileName;
}

@@ -119,9 +126,10 @@ public boolean isCollapsed() {

/** Convert the stack frame to a JSON representation. */
public JSONObject toJSON() {
String file = getFile();
return new JSONObject(
MapBuilder.of(
"file", getFile(),
"file", (file == null) ? "" : file,
"methodName", getMethod(),
"lineNumber", getLine(),
"column", getColumn(),
@@ -136,25 +144,33 @@ public JSONObject toJSON() {
public static StackFrame[] convertJsStackTrace(@Nullable ReadableArray stack) {
int size = stack != null ? stack.size() : 0;
StackFrame[] result = new StackFrame[size];
for (int i = 0; i < size; i++) {
ReadableType type = stack.getType(i);
if (type == ReadableType.Map) {
ReadableMap frame = stack.getMap(i);
String methodName = frame.getString("methodName");
String fileName = frame.getString("file");
boolean collapse =
frame.hasKey("collapse") && !frame.isNull("collapse") && frame.getBoolean("collapse");
int lineNumber = -1;
if (frame.hasKey(LINE_NUMBER_KEY) && !frame.isNull(LINE_NUMBER_KEY)) {
lineNumber = frame.getInt(LINE_NUMBER_KEY);
}
int columnNumber = -1;
if (frame.hasKey(COLUMN_KEY) && !frame.isNull(COLUMN_KEY)) {
columnNumber = frame.getInt(COLUMN_KEY);
if (stack != null) {
for (int i = 0; i < size; i++) {
ReadableType type = stack.getType(i);
if (type == ReadableType.Map) {
ReadableMap frame = stack.getMap(i);
Assertions.assertNotNull(frame);
String methodName = frame.getString("methodName");
String fileName = frame.getString("file");
Assertions.assertNotNull(fileName);
Assertions.assertNotNull(methodName);
boolean collapse =
frame.hasKey("collapse") && !frame.isNull("collapse") && frame.getBoolean("collapse");
int lineNumber = -1;
if (frame.hasKey(LINE_NUMBER_KEY) && !frame.isNull(LINE_NUMBER_KEY)) {
lineNumber = frame.getInt(LINE_NUMBER_KEY);
}
int columnNumber = -1;
if (frame.hasKey(COLUMN_KEY) && !frame.isNull(COLUMN_KEY)) {
columnNumber = frame.getInt(COLUMN_KEY);
}
result[i] = new StackFrameImpl(fileName, methodName, lineNumber, columnNumber, collapse);
} else if (type == ReadableType.String) {
String stackFrame = stack.getString(i);
if (stackFrame != null) {
result[i] = new StackFrameImpl(null, stackFrame, -1, -1);
}
}
result[i] = new StackFrameImpl(fileName, methodName, lineNumber, columnNumber, collapse);
} else if (type == ReadableType.String) {
result[i] = new StackFrameImpl(null, stack.getString(i), -1, -1);
}
}
return result;
@@ -203,15 +219,22 @@ public static StackFrame[] convertJsStackTrace(String stack) {
} else if (matcher1.find()) {
matcher = matcher1;
} else {
result[i] = new StackFrameImpl(null, stackTrace[i], -1, -1);
String unmatchedStackFrame = stackTrace[i];
if (unmatchedStackFrame != null) {
result[i] = new StackFrameImpl(null, unmatchedStackFrame, -1, -1);
}
continue;
}
String fileName = matcher.group(2);
String methodName = matcher.group(1) == null ? "(unknown)" : matcher.group(1);
String lineString = matcher.group(3);
String columnString = matcher.group(4);
if (methodName == null || fileName == null || lineString == null || columnString == null) {
continue;
}
result[i] =
new StackFrameImpl(
matcher.group(2),
matcher.group(1) == null ? "(unknown)" : matcher.group(1),
Integer.parseInt(matcher.group(3)),
Integer.parseInt(matcher.group(4)));
fileName, methodName, Integer.parseInt(lineString), Integer.parseInt(columnString));
}
return result;
}
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ public interface StackFrame {
public val file: String?

/** Get the name of the method this frame points to. */
public val method: String?
public val method: String

/** Get the line number this frame points to in the file returned by [.getFile]. */
public val line: Int
@@ -40,5 +40,5 @@ public interface StackFrame {
public val isCollapsed: Boolean

/** Convert the stack frame to a JSON representation. */
public fun toJSON(): JSONObject?
public fun toJSON(): JSONObject
}
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ class JSDebuggerWebSocketClientTest {
val client = spy(JSDebuggerWebSocketClient())
val injectedObjects = mapOf("key1" to "value1", "key2" to "value2")
client.loadBundle(
"http://localhost:8080/index.js", injectedObjects as HashMap<String, String>?, cb)
"http://localhost:8080/index.js", injectedObjects as HashMap<String, String>, cb)
verify(client)
.sendMessage(
0,
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ class MultipartStreamReaderTest {

val callback: CallCountTrackingChunkCallback =
object : CallCountTrackingChunkCallback() {
override fun onChunkComplete(headers: Map<String, String>?, body: Buffer, done: Boolean) {
override fun onChunkComplete(headers: Map<String, String>, body: Buffer, done: Boolean) {
super.onChunkComplete(headers, body, done)

assertThat(done).isTrue
@@ -68,7 +68,7 @@ class MultipartStreamReaderTest {

val callback: CallCountTrackingChunkCallback =
object : CallCountTrackingChunkCallback() {
override fun onChunkComplete(headers: Map<String, String>?, body: Buffer, done: Boolean) {
override fun onChunkComplete(headers: Map<String, String>, body: Buffer, done: Boolean) {
super.onChunkComplete(headers, body, done)

assertThat(done).isEqualTo(callCount == 3)
@@ -125,7 +125,7 @@ class MultipartStreamReaderTest {
var callCount = 0
private set

override fun onChunkComplete(headers: Map<String, String>?, body: Buffer, done: Boolean) {
override fun onChunkComplete(headers: Map<String, String>, body: Buffer, done: Boolean) {
callCount++
}

Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ class StackTraceHelperTest {
fun testParseStackFrameWithInvalidFrame() {
val frame = StackTraceHelper.convertJsStackTrace("Test.bundle:ten:twenty").get(0)
assertThat(frame.method).isEqualTo("Test.bundle:ten:twenty")
assertThat(frame.fileName).isEqualTo("")
assertThat(frame.fileName).isEqualTo(null)
assertThat(frame.line).isEqualTo(-1)
assertThat(frame.column).isEqualTo(-1)
}
@@ -56,7 +56,7 @@ class StackTraceHelperTest {
fun testParseStackFrameWithNativeCodeFrame() {
val frame = StackTraceHelper.convertJsStackTrace("forEach@[native code]").get(0)
assertThat(frame.method).isEqualTo("forEach@[native code]")
assertThat(frame.fileName).isEqualTo("")
assertThat(frame.fileName).isEqualTo(null)
assertThat(frame.line).isEqualTo(-1)
assertThat(frame.column).isEqualTo(-1)
}

Unchanged files with check annotations Beta

fromEnc: buffer$Encoding,
toEnc: buffer$Encoding,
): Node$Buffer;
declare var Buffer: Node$Buffer;

Check warning on line 200 in flow-typed/environment/node.js

GitHub Actions / test_js (22)

'Buffer' is already declared in the upper scope on line 53 column 15

Check warning on line 200 in flow-typed/environment/node.js

GitHub Actions / test_js (20)

'Buffer' is already declared in the upper scope on line 53 column 15

Check warning on line 200 in flow-typed/environment/node.js

GitHub Actions / test_js (18)

'Buffer' is already declared in the upper scope on line 53 column 15
}
type child_process$execOpts = {
return assets[assetId - 1];
}
module.exports = {registerAsset, getAssetByID};

Check warning on line 43 in packages/assets/registry.js

GitHub Actions / test_js (22)

Use `export` syntax instead of CommonJS `module.exports`

Check warning on line 43 in packages/assets/registry.js

GitHub Actions / test_js (20)

Use `export` syntax instead of CommonJS `module.exports`

Check warning on line 43 in packages/assets/registry.js

GitHub Actions / test_js (18)

Use `export` syntax instead of CommonJS `module.exports`
nativeTypeDiffingTypesAliases,
nativeTypeDiffingTypesMethodParamLookup,
nativeTypeDiffingTypesMethodLookup,
_,

Check warning on line 85 in packages/react-native-compatibility-check/src/__tests__/TypeDiffing-test.js

GitHub Actions / test_js (22)

'_' is assigned a value but never used

Check warning on line 85 in packages/react-native-compatibility-check/src/__tests__/TypeDiffing-test.js

GitHub Actions / test_js (20)

'_' is assigned a value but never used

Check warning on line 85 in packages/react-native-compatibility-check/src/__tests__/TypeDiffing-test.js

GitHub Actions / test_js (18)

'_' is assigned a value but never used
nativeTypeDiffingTypesEnums,
] = getModule(
'native-module-type-diffing-types',
});
});
describe('scrollTo', () => {

Check warning on line 641 in packages/react-native-fantom/src/__tests__/Fantom-itest.js

GitHub Actions / test_js (22)

Describe block title is used multiple times in the same describe block

Check warning on line 641 in packages/react-native-fantom/src/__tests__/Fantom-itest.js

GitHub Actions / test_js (20)

Describe block title is used multiple times in the same describe block

Check warning on line 641 in packages/react-native-fantom/src/__tests__/Fantom-itest.js

GitHub Actions / test_js (18)

Describe block title is used multiple times in the same describe block
it('throws error if called on node that is not scroll view', () => {
const root = Fantom.createRoot();
let maybeNode;
import type AnimatedValue from '../nodes/AnimatedValue';
import NativeAnimatedHelper from '../../../src/private/animated/NativeAnimatedHelper';
import * as ReactNativeFeatureFlags from '../../../src/private/featureflags/ReactNativeFeatureFlags';

Check warning on line 16 in packages/react-native/Libraries/Animated/animations/Animation.js

GitHub Actions / test_js (22)

'ReactNativeFeatureFlags' is defined but never used

Check warning on line 16 in packages/react-native/Libraries/Animated/animations/Animation.js

GitHub Actions / test_js (20)

'ReactNativeFeatureFlags' is defined but never used

Check warning on line 16 in packages/react-native/Libraries/Animated/animations/Animation.js

GitHub Actions / test_js (18)

'ReactNativeFeatureFlags' is defined but never used
import AnimatedProps from '../nodes/AnimatedProps';
export type EndResult = {finished: boolean, value?: number, ...};
remoteModuleConfig: remoteModulesConfig,
};
module.exports = MessageQueueTestConfig;

Check warning on line 38 in packages/react-native/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js

GitHub Actions / test_js (22)

Use `export` syntax instead of CommonJS `module.exports`

Check warning on line 38 in packages/react-native/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js

GitHub Actions / test_js (20)

Use `export` syntax instead of CommonJS `module.exports`

Check warning on line 38 in packages/react-native/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js

GitHub Actions / test_js (18)

Use `export` syntax instead of CommonJS `module.exports`
testHook2: function () {},
};
module.exports = MessageQueueTestModule;

Check warning on line 22 in packages/react-native/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js

GitHub Actions / test_js (22)

Use `export` syntax instead of CommonJS `module.exports`

Check warning on line 22 in packages/react-native/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js

GitHub Actions / test_js (20)

Use `export` syntax instead of CommonJS `module.exports`

Check warning on line 22 in packages/react-native/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js

GitHub Actions / test_js (18)

Use `export` syntax instead of CommonJS `module.exports`
release() {},
};
module.exports = BlobModule;

Check warning on line 16 in packages/react-native/Libraries/Blob/__mocks__/BlobModule.js

GitHub Actions / test_js (22)

Use `export` syntax instead of CommonJS `module.exports`

Check warning on line 16 in packages/react-native/Libraries/Blob/__mocks__/BlobModule.js

GitHub Actions / test_js (20)

Use `export` syntax instead of CommonJS `module.exports`

Check warning on line 16 in packages/react-native/Libraries/Blob/__mocks__/BlobModule.js

GitHub Actions / test_js (18)

Use `export` syntax instead of CommonJS `module.exports`
},
};
module.exports = FileReaderModule;

Check warning on line 20 in packages/react-native/Libraries/Blob/__mocks__/FileReaderModule.js

GitHub Actions / test_js (22)

Use `export` syntax instead of CommonJS `module.exports`

Check warning on line 20 in packages/react-native/Libraries/Blob/__mocks__/FileReaderModule.js

GitHub Actions / test_js (20)

Use `export` syntax instead of CommonJS `module.exports`

Check warning on line 20 in packages/react-native/Libraries/Blob/__mocks__/FileReaderModule.js

GitHub Actions / test_js (18)

Use `export` syntax instead of CommonJS `module.exports`
MeasureLayoutOnSuccessCallback,
MeasureOnSuccessCallback,
} from '../../../src/private/types/HostInstance';
import type {AccessibilityRole} from '../../Components/View/ViewAccessibility';

Check warning on line 16 in packages/react-native/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js

GitHub Actions / test_js (22)

'AccessibilityRole' is defined but never used

Check warning on line 16 in packages/react-native/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js

GitHub Actions / test_js (20)

'AccessibilityRole' is defined but never used

Check warning on line 16 in packages/react-native/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js

GitHub Actions / test_js (18)

'AccessibilityRole' is defined but never used
import typeof DrawerLayoutAndroidCommon from './DrawerLayoutAndroid.js';
import type {
DrawerLayoutAndroidMethods,