@@ -91,7 +91,7 @@ public class RNSentryModuleImpl {
91
91
private static final ILogger logger = new AndroidLogger (NAME );
92
92
private static final BuildInfoProvider buildInfo = new BuildInfoProvider (logger );
93
93
private static final String modulesPath = "modules.json" ;
94
- private static final Charset UTF_8 = Charset .forName ("UTF-8" );
94
+ private static final Charset UTF_8 = Charset .forName ("UTF-8" ); // NOPMD - Allow using UTF-8
95
95
96
96
private final ReactApplicationContext reactApplicationContext ;
97
97
private final PackageInfo packageInfo ;
@@ -270,7 +270,7 @@ public void initNativeSdk(final ReadableMap rnOptions, Promise promise) {
270
270
if (null != ex && ex .getType ().contains ("JavascriptException" )) {
271
271
return null ;
272
272
}
273
- } catch (Throwable ignored ) {
273
+ } catch (Throwable ignored ) { // NOPMD - We don't want to crash in any case
274
274
// We do nothing
275
275
}
276
276
@@ -356,30 +356,29 @@ public void crash() {
356
356
throw new RuntimeException ("TEST - Sentry Client Crash (only works in release mode)" );
357
357
}
358
358
359
- public void addListener (String _eventType ) {
359
+ public void addListener (String eventType ) {
360
360
// Is must be defined otherwise the generated interface from TS won't be fulfilled
361
361
logger .log (SentryLevel .ERROR , "addListener of NativeEventEmitter can't be used on Android!" );
362
362
}
363
363
364
- public void removeListeners (double _id ) {
364
+ public void removeListeners (double id ) {
365
365
// Is must be defined otherwise the generated interface from TS won't be fulfilled
366
366
logger .log (
367
367
SentryLevel .ERROR , "removeListeners of NativeEventEmitter can't be used on Android!" );
368
368
}
369
369
370
370
public void fetchModules (Promise promise ) {
371
371
final AssetManager assets = this .getReactApplicationContext ().getResources ().getAssets ();
372
- try (final InputStream stream =
373
- new BufferedInputStream (assets .open (RNSentryModuleImpl .modulesPath ))) {
372
+ try (InputStream stream = new BufferedInputStream (assets .open (modulesPath ))) {
374
373
int size = stream .available ();
375
374
byte [] buffer = new byte [size ];
376
375
stream .read (buffer );
377
376
stream .close ();
378
- String modulesJson = new String (buffer , RNSentryModuleImpl . UTF_8 );
377
+ String modulesJson = new String (buffer , UTF_8 );
379
378
promise .resolve (modulesJson );
380
379
} catch (FileNotFoundException e ) {
381
380
promise .resolve (null );
382
- } catch (Throwable e ) {
381
+ } catch (Throwable e ) { // NOPMD - We don't want to crash in any case
383
382
logger .log (SentryLevel .WARNING , "Fetching JS Modules failed." );
384
383
promise .resolve (null );
385
384
}
@@ -462,7 +461,7 @@ public void fetchNativeFrames(Promise promise) {
462
461
map .putInt ("frozenFrames" , frozenFrames );
463
462
464
463
promise .resolve (map );
465
- } catch (Throwable ignored ) {
464
+ } catch (Throwable ignored ) { // NOPMD - We don't want to crash in any case
466
465
logger .log (SentryLevel .WARNING , "Error fetching native frames." );
467
466
promise .resolve (null );
468
467
}
@@ -493,7 +492,7 @@ public void captureEnvelope(String rawBytes, ReadableMap options, Promise promis
493
492
try {
494
493
InternalSentrySdk .captureEnvelope (
495
494
bytes , !options .hasKey ("hardCrashed" ) || !options .getBoolean ("hardCrashed" ));
496
- } catch (Throwable e ) {
495
+ } catch (Throwable e ) { // NOPMD - We don't want to crash in any case
497
496
logger .log (SentryLevel .ERROR , "Error while capturing envelope" );
498
497
promise .resolve (false );
499
498
}
@@ -511,7 +510,7 @@ public void captureScreenshot(Promise promise) {
511
510
512
511
final byte [] raw = takeScreenshotOnUiThread (activity );
513
512
514
- if (raw == null ) {
513
+ if (raw == null || raw . length == 0 ) {
515
514
logger .log (SentryLevel .WARNING , "Screenshot is null, screen was not captured." );
516
515
promise .resolve (null );
517
516
return ;
@@ -550,7 +549,7 @@ private static byte[] takeScreenshotOnUiThread(Activity activity) {
550
549
doneSignal .await (SCREENSHOT_TIMEOUT_SECONDS , SECONDS );
551
550
} catch (InterruptedException e ) {
552
551
logger .log (SentryLevel .ERROR , "Screenshot process was interrupted." );
553
- return null ;
552
+ return new byte [ 0 ] ;
554
553
}
555
554
556
555
return bytesWrapper [0 ];
@@ -627,7 +626,7 @@ public void setUser(final ReadableMap userKeys, final ReadableMap userDataKeys)
627
626
}
628
627
629
628
if (userDataKeys != null ) {
630
- HashMap <String , String > userDataMap = new HashMap <>();
629
+ Map <String , String > userDataMap = new HashMap <>();
631
630
ReadableMapKeySetIterator it = userDataKeys .keySetIterator ();
632
631
while (it .hasNextKey ()) {
633
632
String key = it .nextKey ();
@@ -694,7 +693,7 @@ public void setContext(final String key, final ReadableMap context) {
694
693
return ;
695
694
}
696
695
697
- final HashMap <String , Object > contextHashMap = context .toHashMap ();
696
+ final Map <String , Object > contextHashMap = context .toHashMap ();
698
697
scope .setContexts (key , contextHashMap );
699
698
});
700
699
}
@@ -726,7 +725,7 @@ public void enableNativeFramesTracking() {
726
725
frameMetricsAggregator .add (currentActivity );
727
726
728
727
logger .log (SentryLevel .INFO , "FrameMetricsAggregator installed." );
729
- } catch (Throwable ignored ) {
728
+ } catch (Throwable ignored ) { // NOPMD - We don't want to crash in any case
730
729
// throws ConcurrentModification when calling addOnFrameMetricsAvailableListener
731
730
// this is a best effort since we can't reproduce it
732
731
logger .log (SentryLevel .ERROR , "Error adding Activity to frameMetricsAggregator." );
@@ -785,7 +784,7 @@ public WritableMap startProfiling(boolean platformProfilers) {
785
784
}
786
785
787
786
result .putBoolean ("started" , true );
788
- } catch (Throwable e ) {
787
+ } catch (Throwable e ) { // NOPMD - We don't want to crash in any case
789
788
result .putBoolean ("started" , false );
790
789
result .putString ("error" , e .toString ());
791
790
}
@@ -825,7 +824,7 @@ public WritableMap stopProfiling() {
825
824
androidProfile .putString ("build_id" , getProguardUuid ());
826
825
result .putMap ("androidProfile" , androidProfile );
827
826
}
828
- } catch (Throwable e ) {
827
+ } catch (Throwable e ) { // NOPMD - We don't want to crash in any case
829
828
result .putString ("error" , e .toString ());
830
829
} finally {
831
830
if (output != null ) {
@@ -834,7 +833,7 @@ public WritableMap stopProfiling() {
834
833
if (!wasProfileSuccessfullyDeleted ) {
835
834
logger .log (SentryLevel .WARNING , "Profile not deleted from:" + output .getAbsolutePath ());
836
835
}
837
- } catch (Throwable e ) {
836
+ } catch (Throwable e ) { // NOPMD - We don't want to crash in any case
838
837
logger .log (SentryLevel .WARNING , "Profile not deleted from:" + output .getAbsolutePath ());
839
838
}
840
839
}
@@ -848,7 +847,7 @@ public WritableMap stopProfiling() {
848
847
}
849
848
isProguardDebugMetaLoaded = true ;
850
849
final @ Nullable List <Properties > debugMetaList =
851
- ( new AssetsDebugMetaLoader (this .getReactApplicationContext (), logger ) ).loadDebugMeta ();
850
+ new AssetsDebugMetaLoader (this .getReactApplicationContext (), logger ).loadDebugMeta ();
852
851
if (debugMetaList == null ) {
853
852
return null ;
854
853
}
@@ -866,7 +865,7 @@ public WritableMap stopProfiling() {
866
865
}
867
866
868
867
private String readStringFromFile (File path ) throws IOException {
869
- try (final BufferedReader br = new BufferedReader (new FileReader (path )); ) {
868
+ try (BufferedReader br = new BufferedReader (new FileReader (path )); ) {
870
869
871
870
final StringBuilder text = new StringBuilder ();
872
871
String line ;
@@ -943,7 +942,7 @@ private void setEventEnvironmentTag(SentryEvent event, String environment) {
943
942
private void addPackages (SentryEvent event , SdkVersion sdk ) {
944
943
SdkVersion eventSdk = event .getSdk ();
945
944
if (eventSdk != null
946
- && eventSdk . getName (). equals ( "sentry.javascript.react-native" )
945
+ && "sentry.javascript.react-native" . equals ( eventSdk . getName () )
947
946
&& sdk != null ) {
948
947
List <SentryPackage > sentryPackages = sdk .getPackages ();
949
948
if (sentryPackages != null ) {
0 commit comments