Fix more detekt and lint issues and remove them from the baseline.

This commit is contained in:
tzugen 2021-05-27 11:41:00 +02:00
parent 6dc0eb7ecc
commit e21ae1299b
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
10 changed files with 11 additions and 104 deletions

View File

@ -26,10 +26,10 @@ class AvatarRequestHandler(
?: throw IllegalArgumentException("Nullable username") ?: throw IllegalArgumentException("Nullable username")
val response = apiClient.getAvatar(username) val response = apiClient.getAvatar(username)
if (response.hasError()) { if (response.hasError() || response.stream == null) {
throw IOException("${response.apiError}") throw IOException("${response.apiError}")
} else { } else {
return Result(Okio.source(response.stream), Picasso.LoadedFrom.NETWORK) return Result(Okio.source(response.stream!!), Picasso.LoadedFrom.NETWORK)
} }
} }
} }

View File

@ -24,10 +24,10 @@ class CoverArtRequestHandler(private val apiClient: SubsonicAPIClient) : Request
?: throw IllegalArgumentException("Nullable id") ?: throw IllegalArgumentException("Nullable id")
val response = apiClient.getCoverArt(id) val response = apiClient.getCoverArt(id)
if (response.hasError()) { if (response.hasError() || response.stream == null) {
throw IOException("${response.apiError}") throw IOException("${response.apiError}")
} else { } else {
return Result(Okio.source(response.stream), NETWORK) return Result(Okio.source(response.stream!!), NETWORK)
} }
} }
} }

View File

@ -67,18 +67,10 @@
<ID>NestedBlockDepth:DownloadFile.kt$DownloadFile.DownloadTask$override fun execute()</ID> <ID>NestedBlockDepth:DownloadFile.kt$DownloadFile.DownloadTask$override fun execute()</ID>
<ID>NestedBlockDepth:DownloadHandler.kt$DownloadHandler$private fun downloadRecursively( fragment: Fragment, id: String, name: String?, isShare: Boolean, isDirectory: Boolean, save: Boolean, append: Boolean, autoPlay: Boolean, shuffle: Boolean, background: Boolean, playNext: Boolean, unpin: Boolean, isArtist: Boolean )</ID> <ID>NestedBlockDepth:DownloadHandler.kt$DownloadHandler$private fun downloadRecursively( fragment: Fragment, id: String, name: String?, isShare: Boolean, isDirectory: Boolean, save: Boolean, append: Boolean, autoPlay: Boolean, shuffle: Boolean, background: Boolean, playNext: Boolean, unpin: Boolean, isArtist: Boolean )</ID>
<ID>NestedBlockDepth:MediaPlayerService.kt$MediaPlayerService$private fun setupOnSongCompletedHandler()</ID> <ID>NestedBlockDepth:MediaPlayerService.kt$MediaPlayerService$private fun setupOnSongCompletedHandler()</ID>
<ID>ReturnCount:ActiveServerProvider.kt$ActiveServerProvider$ fun getActiveServer(): ServerSetting</ID>
<ID>ReturnCount:CommunicationErrorHandler.kt$CommunicationErrorHandler.Companion$fun getErrorMessage(error: Throwable, context: Context): String</ID> <ID>ReturnCount:CommunicationErrorHandler.kt$CommunicationErrorHandler.Companion$fun getErrorMessage(error: Throwable, context: Context): String</ID>
<ID>ReturnCount:FileLoggerTree.kt$FileLoggerTree$ private fun getNextLogFile()</ID>
<ID>ReturnCount:MediaPlayerService.kt$MediaPlayerService$private fun generateAction(context: Context, requestCode: Int): NotificationCompat.Action?</ID>
<ID>ReturnCount:RESTMusicService.kt$RESTMusicService$@Throws(Exception::class) override fun getAvatar( username: String?, size: Int, saveToFile: Boolean, highQuality: Boolean ): Bitmap?</ID>
<ID>ReturnCount:RESTMusicService.kt$RESTMusicService$@Throws(Exception::class) override fun getCoverArt( entry: MusicDirectory.Entry?, size: Int, saveToFile: Boolean, highQuality: Boolean ): Bitmap?</ID> <ID>ReturnCount:RESTMusicService.kt$RESTMusicService$@Throws(Exception::class) override fun getCoverArt( entry: MusicDirectory.Entry?, size: Int, saveToFile: Boolean, highQuality: Boolean ): Bitmap?</ID>
<ID>ReturnCount:ServerRowAdapter.kt$ServerRowAdapter$ private fun popupMenuItemClick(menuItem: MenuItem, position: Int): Boolean</ID> <ID>ReturnCount:ServerRowAdapter.kt$ServerRowAdapter$ private fun popupMenuItemClick(menuItem: MenuItem, position: Int): Boolean</ID>
<ID>ReturnCount:TrackCollectionFragment.kt$TrackCollectionFragment$override fun onContextItemSelected(menuItem: MenuItem): Boolean</ID> <ID>ReturnCount:TrackCollectionFragment.kt$TrackCollectionFragment$override fun onContextItemSelected(menuItem: MenuItem): Boolean</ID>
<ID>ReturnCount:TrackCollectionFragment.kt$TrackCollectionFragment$override fun onOptionsItemSelected(item: MenuItem): Boolean</ID>
<ID>SwallowedException:LocalMediaPlayer.kt$LocalMediaPlayer$catch (e: Throwable) { // Froyo or lower }</ID>
<ID>SwallowedException:LocalMediaPlayer.kt$LocalMediaPlayer$catch (e: Throwable) { }</ID>
<ID>SwallowedException:MediaPlayerService.kt$MediaPlayerService$catch (x: IndexOutOfBoundsException) { // Ignored }</ID>
<ID>SwallowedException:NavigationActivity.kt$NavigationActivity$catch (e: Resources.NotFoundException) { destination.id.toString() }</ID> <ID>SwallowedException:NavigationActivity.kt$NavigationActivity$catch (e: Resources.NotFoundException) { destination.id.toString() }</ID>
<ID>ThrowsCount:ApiCallResponseChecker.kt$ApiCallResponseChecker.Companion$@Throws(SubsonicRESTException::class, IOException::class) fun checkResponseSuccessful(response: Response&lt;out SubsonicResponse&gt;)</ID> <ID>ThrowsCount:ApiCallResponseChecker.kt$ApiCallResponseChecker.Companion$@Throws(SubsonicRESTException::class, IOException::class) fun checkResponseSuccessful(response: Response&lt;out SubsonicResponse&gt;)</ID>
<ID>TooGenericExceptionCaught:DownloadFile.kt$DownloadFile$e: Exception</ID> <ID>TooGenericExceptionCaught:DownloadFile.kt$DownloadFile$e: Exception</ID>
@ -89,7 +81,6 @@
<ID>TooGenericExceptionCaught:LocalMediaPlayer.kt$LocalMediaPlayer$x: Exception</ID> <ID>TooGenericExceptionCaught:LocalMediaPlayer.kt$LocalMediaPlayer$x: Exception</ID>
<ID>TooGenericExceptionCaught:LocalMediaPlayer.kt$LocalMediaPlayer.PositionCache$e: Exception</ID> <ID>TooGenericExceptionCaught:LocalMediaPlayer.kt$LocalMediaPlayer.PositionCache$e: Exception</ID>
<ID>TooGenericExceptionCaught:MediaPlayerService.kt$MediaPlayerService$e: Exception</ID> <ID>TooGenericExceptionCaught:MediaPlayerService.kt$MediaPlayerService$e: Exception</ID>
<ID>TooGenericExceptionCaught:MediaPlayerService.kt$MediaPlayerService$x: IndexOutOfBoundsException</ID>
<ID>TooGenericExceptionCaught:SongView.kt$SongView$e: Exception</ID> <ID>TooGenericExceptionCaught:SongView.kt$SongView$e: Exception</ID>
<ID>TooGenericExceptionCaught:SubsonicUncaughtExceptionHandler.kt$SubsonicUncaughtExceptionHandler$x: Throwable</ID> <ID>TooGenericExceptionCaught:SubsonicUncaughtExceptionHandler.kt$SubsonicUncaughtExceptionHandler$x: Throwable</ID>
<ID>TooGenericExceptionCaught:VideoPlayer.kt$VideoPlayer$e: Exception</ID> <ID>TooGenericExceptionCaught:VideoPlayer.kt$VideoPlayer$e: Exception</ID>
@ -98,7 +89,6 @@
<ID>TooManyFunctions:MediaPlayerService.kt$MediaPlayerService : Service</ID> <ID>TooManyFunctions:MediaPlayerService.kt$MediaPlayerService : Service</ID>
<ID>TooManyFunctions:RESTMusicService.kt$RESTMusicService : MusicService</ID> <ID>TooManyFunctions:RESTMusicService.kt$RESTMusicService : MusicService</ID>
<ID>TooManyFunctions:TrackCollectionFragment.kt$TrackCollectionFragment : Fragment</ID> <ID>TooManyFunctions:TrackCollectionFragment.kt$TrackCollectionFragment : Fragment</ID>
<ID>UnusedPrivateMember:RESTMusicService.kt$RESTMusicService.Companion$private const val INDEXES_FOLDER_STORAGE_NAME = "indexes_folder"</ID>
<ID>UtilityClassWithPublicConstructor:CommunicationErrorHandler.kt$CommunicationErrorHandler</ID> <ID>UtilityClassWithPublicConstructor:CommunicationErrorHandler.kt$CommunicationErrorHandler</ID>
<ID>UtilityClassWithPublicConstructor:FragmentTitle.kt$FragmentTitle</ID> <ID>UtilityClassWithPublicConstructor:FragmentTitle.kt$FragmentTitle</ID>
</CurrentIssues> </CurrentIssues>

View File

@ -23,72 +23,6 @@
column="55"/> column="55"/>
</issue> </issue>
<issue
id="DefaultLocale"
message="Implicitly using the default locale is a common source of bugs: Use `toLowerCase(Locale)` instead. For strings meant to be internal use `Locale.ROOT`, otherwise `Locale.getDefault()`."
errorLine1=" String lhs = lhsArtist.getName().toLowerCase();"
errorLine2=" ~~~~~~~~~~~">
<location
file="src/main/java/org/moire/ultrasonic/service/OfflineMusicService.java"
line="97"
column="37"/>
</issue>
<issue
id="DefaultLocale"
message="Implicitly using the default locale is a common source of bugs: Use `toLowerCase(Locale)` instead. For strings meant to be internal use `Locale.ROOT`, otherwise `Locale.getDefault()`."
errorLine1=" String rhs = rhsArtist.getName().toLowerCase();"
errorLine2=" ~~~~~~~~~~~">
<location
file="src/main/java/org/moire/ultrasonic/service/OfflineMusicService.java"
line="98"
column="37"/>
</issue>
<issue
id="DefaultLocale"
message="Implicitly using the default locale is a common source of bugs: Use `toLowerCase(Locale)` instead. For strings meant to be internal use `Locale.ROOT`, otherwise `Locale.getDefault()`."
errorLine1=" int index = lhs.indexOf(String.format(&quot;%s &quot;, article.toLowerCase()));"
errorLine2=" ~~~~~~~~~~~">
<location
file="src/main/java/org/moire/ultrasonic/service/OfflineMusicService.java"
line="115"
column="58"/>
</issue>
<issue
id="DefaultLocale"
message="Implicitly using the default locale is a common source of bugs: Use `toLowerCase(Locale)` instead. For strings meant to be internal use `Locale.ROOT`, otherwise `Locale.getDefault()`."
errorLine1=" index = rhs.indexOf(String.format(&quot;%s &quot;, article.toLowerCase()));"
errorLine2=" ~~~~~~~~~~~">
<location
file="src/main/java/org/moire/ultrasonic/service/OfflineMusicService.java"
line="122"
column="54"/>
</issue>
<issue
id="DefaultLocale"
message="Implicitly using the default locale is a common source of bugs: Use `toLowerCase(Locale)` instead. For strings meant to be internal use `Locale.ROOT`, otherwise `Locale.getDefault()`."
errorLine1=" String query = criteria.getQuery().toLowerCase();"
errorLine2=" ~~~~~~~~~~~">
<location
file="src/main/java/org/moire/ultrasonic/service/OfflineMusicService.java"
line="466"
column="38"/>
</issue>
<issue
id="DefaultLocale"
message="Implicitly using the default locale is a common source of bugs: Use `toLowerCase(Locale)` instead. For strings meant to be internal use `Locale.ROOT`, otherwise `Locale.getDefault()`."
errorLine1=" String[] nameParts = COMPILE.split(name.toLowerCase());"
errorLine2=" ~~~~~~~~~~~">
<location
file="src/main/java/org/moire/ultrasonic/service/OfflineMusicService.java"
line="468"
column="43"/>
</issue>
<issue <issue
id="InlinedApi" id="InlinedApi"
message="Field requires API level 16 (current min is 14): `android.Manifest.permission#READ_EXTERNAL_STORAGE`" message="Field requires API level 16 (current min is 14): `android.Manifest.permission#READ_EXTERNAL_STORAGE`"
@ -484,17 +418,6 @@
column="5"/> column="5"/>
</issue> </issue>
<issue
id="TrulyRandom"
message="Potentially insecure random numbers on Android 4.3 and older. Read https://android-developers.blogspot.com/2013/08/some-securerandom-thoughts.html for more info."
errorLine1=" Random random = new java.security.SecureRandom();"
errorLine2=" ~~~~~~~~~~~~">
<location
file="src/main/java/org/moire/ultrasonic/service/OfflineMusicService.java"
line="633"
column="37"/>
</issue>
<issue <issue
id="AllowAllHostnameVerifier" id="AllowAllHostnameVerifier"
message="Using the `AllowAllHostnameVerifier` HostnameVerifier is unsafe because it always returns true, which could cause insecure network traffic due to trusting TLS/SSL server certificates for wrong hostnames" message="Using the `AllowAllHostnameVerifier` HostnameVerifier is unsafe because it always returns true, which could cause insecure network traffic due to trusting TLS/SSL server certificates for wrong hostnames"

View File

@ -124,7 +124,7 @@ class NavigationActivity : AppCompatActivity() {
navController.addOnDestinationChangedListener { _, destination, _ -> navController.addOnDestinationChangedListener { _, destination, _ ->
val dest: String = try { val dest: String = try {
resources.getResourceName(destination.id) resources.getResourceName(destination.id)
} catch (e: Resources.NotFoundException) { } catch (ignored: Resources.NotFoundException) {
destination.id.toString() destination.id.toString()
} }
Timber.d("Navigated to $dest") Timber.d("Navigated to $dest")

View File

@ -28,7 +28,6 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import androidx.navigation.Navigation import androidx.navigation.Navigation
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import java.security.SecureRandom
import java.util.Collections import java.util.Collections
import java.util.Random import java.util.Random
import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineExceptionHandler
@ -92,7 +91,7 @@ class TrackCollectionFragment : Fragment() {
private var cancellationToken: CancellationToken? = null private var cancellationToken: CancellationToken? = null
private val model: TrackCollectionModel by viewModels() private val model: TrackCollectionModel by viewModels()
private val random: Random = SecureRandom() private val random: Random = Random()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
Util.applyTheme(this.context) Util.applyTheme(this.context)

View File

@ -106,7 +106,7 @@ class LocalMediaPlayer(
i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mediaPlayer.audioSessionId) i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mediaPlayer.audioSessionId)
i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.packageName) i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.packageName)
context.sendBroadcast(i) context.sendBroadcast(i)
} catch (e: Throwable) { } catch (ignored: Throwable) {
// Froyo or lower // Froyo or lower
} }
mediaPlayerLooper = Looper.myLooper() mediaPlayerLooper = Looper.myLooper()
@ -466,7 +466,7 @@ class LocalMediaPlayer(
// the equalizer or visualizer with the player // the equalizer or visualizer with the player
try { try {
nextMediaPlayer!!.audioSessionId = mediaPlayer.audioSessionId nextMediaPlayer!!.audioSessionId = mediaPlayer.audioSessionId
} catch (e: Throwable) { } catch (ignored: Throwable) {
} }
nextMediaPlayer!!.setDataSource(file.path) nextMediaPlayer!!.setDataSource(file.path)

View File

@ -24,7 +24,6 @@ import android.view.KeyEvent
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import org.koin.android.ext.android.inject import org.koin.android.ext.android.inject
import org.koin.core.component.KoinApiExtension
import org.moire.ultrasonic.R import org.moire.ultrasonic.R
import org.moire.ultrasonic.activity.NavigationActivity import org.moire.ultrasonic.activity.NavigationActivity
import org.moire.ultrasonic.app.UApp import org.moire.ultrasonic.app.UApp
@ -49,7 +48,6 @@ import timber.log.Timber
* Android Foreground Service for playing music * Android Foreground Service for playing music
* while the rest of the Ultrasonic App is in the background. * while the rest of the Ultrasonic App is in the background.
*/ */
@KoinApiExtension
@Suppress("LargeClass") @Suppress("LargeClass")
class MediaPlayerService : Service() { class MediaPlayerService : Service() {
private val binder: IBinder = SimpleServiceBinder(this) private val binder: IBinder = SimpleServiceBinder(this)
@ -173,8 +171,7 @@ class MediaPlayerService : Service() {
fun setCurrentPlaying(currentPlayingIndex: Int) { fun setCurrentPlaying(currentPlayingIndex: Int) {
try { try {
localMediaPlayer.setCurrentPlaying(downloader.downloadList[currentPlayingIndex]) localMediaPlayer.setCurrentPlaying(downloader.downloadList[currentPlayingIndex])
} catch (x: IndexOutOfBoundsException) { } catch (ignored: IndexOutOfBoundsException) {
// Ignored
} }
} }

View File

@ -15,7 +15,6 @@ import java.io.FileReader
import java.io.FileWriter import java.io.FileWriter
import java.io.InputStream import java.io.InputStream
import java.io.Reader import java.io.Reader
import java.security.SecureRandom
import java.util.ArrayList import java.util.ArrayList
import java.util.HashSet import java.util.HashSet
import java.util.LinkedList import java.util.LinkedList
@ -45,7 +44,6 @@ import org.moire.ultrasonic.util.FileUtil
import org.moire.ultrasonic.util.Util import org.moire.ultrasonic.util.Util
import timber.log.Timber import timber.log.Timber
// TODO: There are quite a number of deeply nested and complicated functions in this class.. // TODO: There are quite a number of deeply nested and complicated functions in this class..
// Simplify them :) // Simplify them :)
@Suppress("TooManyFunctions") @Suppress("TooManyFunctions")
@ -290,7 +288,7 @@ class OfflineMusicService : MusicService {
if (children.isEmpty()) { if (children.isEmpty()) {
return result return result
} }
val random: Random = SecureRandom() val random = Random()
for (i in 0 until size) { for (i in 0 until size) {
val file = children[random.nextInt(children.size)] val file = children[random.nextInt(children.size)]
result.addChild(createEntry(file, getName(file))) result.addChild(createEntry(file, getName(file)))

View File

@ -53,6 +53,7 @@ import timber.log.Timber
/** /**
* This Music Service implementation connects to a server using the Subsonic REST API * This Music Service implementation connects to a server using the Subsonic REST API
*/ */
@Suppress("LargeClass")
open class RESTMusicService( open class RESTMusicService(
private val subsonicAPIClient: SubsonicAPIClient, private val subsonicAPIClient: SubsonicAPIClient,
private val fileStorage: PermanentFileStorage, private val fileStorage: PermanentFileStorage,
@ -868,7 +869,6 @@ open class RESTMusicService(
companion object { companion object {
private const val MUSIC_FOLDER_STORAGE_NAME = "music_folder" private const val MUSIC_FOLDER_STORAGE_NAME = "music_folder"
private const val INDEXES_STORAGE_NAME = "indexes" private const val INDEXES_STORAGE_NAME = "indexes"
private const val INDEXES_FOLDER_STORAGE_NAME = "indexes_folder"
private const val ARTISTS_STORAGE_NAME = "artists" private const val ARTISTS_STORAGE_NAME = "artists"
} }
} }