Skip to content

Commit 1369aff

Browse files
authored
fix(barcode): resolve crash when barcode does not include raw bytes (react-native-camera#1916)
1 parent 9d1d0ab commit 1369aff

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

android/src/main/java/org/reactnative/camera/events/BarCodeReadEvent.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,15 @@ private WritableMap serializeEventData() {
7070
event.putInt("target", getViewTag());
7171
event.putString("data", mBarCode.getText());
7272

73-
Formatter formatter = new Formatter();
74-
for (byte b : mBarCode.getRawBytes()) {
75-
formatter.format("%02x", b);
76-
}
77-
event.putString("rawData", formatter.toString());
78-
formatter.close();
73+
byte[] rawBytes = mBarCode.getRawBytes();
74+
if (rawBytes != null && rawBytes.length > 0) {
75+
Formatter formatter = new Formatter();
76+
for (byte b : rawBytes) {
77+
formatter.format("%02x", b);
78+
}
79+
event.putString("rawData", formatter.toString());
80+
formatter.close();
81+
}
7982

8083
event.putString("type", mBarCode.getBarcodeFormat().toString());
8184
WritableArray resultPoints = Arguments.createArray();

0 commit comments

Comments
 (0)