fix: when setPreviewSurfaces is not called startEncoding gives a null Pointer #3125
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of changes:
When using the kinesis video stream SDK without any preview surface, the android app closes abruptly with a Null pointer exception.
This happens because setPreviewSurface is the only place that initializes the mPreviewSurfaces. This variable will be passed to startEncoding that will use it as initialized (non null).
I choose to initialize with a LinkedList to have less upfront cost because this variable will be overridden when setPreviewSurface is called.
The exception that lead me to do this change:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.myapplication, PID: 15958 java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object[] java.util.Collection.toArray()' on a null object reference at java.util.ArrayList.addAll(ArrayList.java:588) at com.amazonaws.mobileconnectors.kinesisvideo.camera.CameraFramesSource.startEncoding(CameraFramesSource.java:84) at com.amazonaws.mobileconnectors.kinesisvideo.mediasource.android.AndroidCameraMediaSource.startEncoding(AndroidCameraMediaSource.java:224) at com.amazonaws.mobileconnectors.kinesisvideo.mediasource.android.AndroidCameraMediaSource.start(AndroidCameraMediaSource.java:196) at com.amazonaws.kinesisvideo.internal.client.AbstractKinesisVideoClient.startAllMediaSources(AbstractKinesisVideoClient.java:93)
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.