ignore detekt for"Detekt.TooGenericExceptionCaught" in scenarios where we need to handle NPE explicitly

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2021-06-01 13:56:09 +02:00
parent 40a08394bc
commit e4da772882
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B

View File

@ -262,6 +262,7 @@ class ChatController(args: Bundle) :
disposableList.add(d)
}
@Suppress("Detekt.TooGenericExceptionCaught")
override fun onNext(roomOverall: RoomOverall) {
currentConversation = roomOverall.ocs.data
loadAvatarForStatusBar()
@ -969,6 +970,7 @@ class ChatController(args: Bundle) :
disposableList.add(d)
}
@Suppress("Detekt.TooGenericExceptionCaught")
override fun onNext(roomOverall: RoomOverall) {
inConversation = true
currentConversation?.sessionId = roomOverall.ocs.data.sessionId
@ -1126,14 +1128,21 @@ class ChatController(args: Bundle) :
// unused atm
}
@Suppress("Detekt.TooGenericExceptionCaught")
override fun onNext(genericOverall: GenericOverall) {
myFirstMessage = message
try {
if (binding.popupBubbleView.isShown == true) {
binding.popupBubbleView.hide()
}
binding.messagesListView.smoothScrollToPosition(0)
} catch (npe: NullPointerException) {
// view binding can be null
// since this is called asynchrously and UI might have been destroyed in the meantime
Log.i(TAG, "UI destroyed - view binding already gone")
}
}
override fun onError(e: Throwable) {
@ -1236,7 +1245,9 @@ class ChatController(args: Bundle) :
disposableList.add(d)
}
@Suppress("Detekt.TooGenericExceptionCaught")
override fun onNext(response: Response<*>) {
try {
if (response.code() == 304) {
pullChatMessages(1, setReadMarker, xChatLastCommonRead)
} else if (response.code() == 412) {
@ -1244,6 +1255,11 @@ class ChatController(args: Bundle) :
} else {
processMessages(response, true, finalTimeout)
}
} catch (npe: NullPointerException) {
// view binding can be null
// since this is called asynchrously and UI might have been destroyed in the meantime
Log.i(TAG, "UI destroyed - view binding already gone")
}
}
override fun onError(e: Throwable) {
@ -1267,12 +1283,19 @@ class ChatController(args: Bundle) :
disposableList.add(d)
}
@Suppress("Detekt.TooGenericExceptionCaught")
override fun onNext(response: Response<*>) {
try {
if (response.code() == 412) {
pastPreconditionFailed = true
} else {
processMessages(response, false, 0)
}
} catch (npe: NullPointerException) {
// view binding can be null
// since this is called asynchrously and UI might have been destroyed in the meantime
Log.i(TAG, "UI destroyed - view binding already gone")
}
}
override fun onError(e: Throwable) {
@ -1316,9 +1339,9 @@ class ChatController(args: Bundle) :
cancelNotificationsForCurrentConversation()
isFirstMessagesProcessing = false
binding.progressBar?.visibility = View.GONE
binding.progressBar.visibility = View.GONE
binding.messagesListView?.visibility = View.VISIBLE
binding.messagesListView.visibility = View.VISIBLE
}
var countGroupedMessages = 0
@ -1383,10 +1406,10 @@ class ChatController(args: Bundle) :
adapter?.itemCount == 0
if (!shouldAddNewMessagesNotice && !shouldScroll) {
if (!binding.popupBubbleView?.isShown!!) {
if (!binding.popupBubbleView.isShown) {
newMessagesCount = 1
binding.popupBubbleView?.show()
} else if (binding.popupBubbleView?.isShown == true) {
binding.popupBubbleView.show()
} else if (binding.popupBubbleView.isShown == true) {
newMessagesCount++
}
} else {
@ -1671,13 +1694,14 @@ class ChatController(args: Bundle) :
override fun onSubscribe(d: Disposable) {
// unused atm
}
override fun onNext(roomOverall: RoomOverall) {
val bundle = Bundle()
bundle.putParcelable(KEY_USER_ENTITY, conversationUser)
bundle.putString(KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken())
bundle.putString(KEY_ROOM_ID, roomOverall.getOcs().getData().getRoomId())
// FIXME once APIv2 or later is used only, the createRoom already returns all the data
// FIXME once APIv2+ is used only, the createRoom already returns all the data
ncApi!!.getRoom(
credentials,
ApiUtils.getUrlForRoom(
@ -1691,6 +1715,7 @@ class ChatController(args: Bundle) :
override fun onSubscribe(d: Disposable) {
// unused atm
}
override fun onNext(roomOverall: RoomOverall) {
bundle.putParcelable(
KEY_ACTIVE_CONVERSATION,
@ -1844,7 +1869,11 @@ class ChatController(args: Bundle) :
switch (webSocketCommunicationEvent.getType()) {
case "refreshChat":
if (webSocketCommunicationEvent.getHashMap().get(BundleKeys.KEY_INTERNAL_USER_ID).equals(Long.toString(conversationUser.getId()))) {
if (
webSocketCommunicationEvent
.getHashMap().get(BundleKeys.KEY_INTERNAL_USER_ID)
.equals(Long.toString(conversationUser.getId()))
) {
if (roomToken.equals(webSocketCommunicationEvent.getHashMap().get(BundleKeys.KEY_ROOM_TOKEN))) {
pullChatMessages(2);
}