Skip to content

Commit cc2cf1a

Browse files
committed
go through (and fix) warnings from IntelliJ
1 parent 20cf347 commit cc2cf1a

27 files changed

Lines changed: 66 additions & 61 deletions

src/main/kotlin/ch/derlin/bbdata/AsyncConfig.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ch.derlin.bbdata
22

3+
import org.slf4j.Logger
34
import org.slf4j.LoggerFactory
45
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler
56
import org.springframework.beans.factory.annotation.Value
@@ -32,7 +33,7 @@ import java.util.concurrent.ThreadPoolExecutor
3233
class AsyncExecutorCustomizer : TaskExecutorCustomizer {
3334
@Value("\${spring.task.execution.pool.queue-capacity}")
3435
val queueCapacity: Int = -1
35-
val logger = LoggerFactory.getLogger(AsyncExecutorCustomizer::class.java)
36+
val logger: Logger = LoggerFactory.getLogger(AsyncExecutorCustomizer::class.java)
3637

3738
override fun customize(taskExecutor: ThreadPoolTaskExecutor?) {
3839
taskExecutor?.let { executor ->
@@ -55,14 +56,14 @@ class AsyncConfig : AsyncConfigurer {
5556

5657
class AsyncExceptionHandler : AsyncUncaughtExceptionHandler {
5758

58-
val logger = LoggerFactory.getLogger(AsyncExceptionHandler::class.java)
59+
val logger: Logger = LoggerFactory.getLogger(AsyncExceptionHandler::class.java)
5960

6061
/**
6162
* Ensure we get the exception logged.
6263
* Attention: this will be called only on async method with void return type !
6364
*/
6465
override fun handleUncaughtException(throwable: Throwable, method: Method, vararg params: Any) {
65-
val niceParams = params.take(2).map { it.toString() }.joinToString(",")
66+
val niceParams = params.take(2).joinToString(",") { it.toString() }
6667
logger.error("in ${method.name} with ${params.size} params: $niceParams ...", throwable)
6768
}
6869
}

src/main/kotlin/ch/derlin/bbdata/BBDataApplication.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement
2222
import org.springframework.web.servlet.config.annotation.CorsRegistry
2323
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
2424
import javax.annotation.PostConstruct
25+
import kotlin.system.exitProcess
2526

2627

2728
@SpringBootApplication
@@ -107,7 +108,7 @@ class CachingConfig {
107108
// forbid in-memory caching if launching the app in split mode (input only or output only)
108109
logger.error("Using in-memory caching with split application (input|output in different JVMs) can lead to security issues." +
109110
"Please, either disable caching or use an external cache such as redis.")
110-
System.exit(1)
111+
exitProcess(1)
111112
}
112113
}
113114
}

src/main/kotlin/ch/derlin/bbdata/Excluders.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ExcludeAutoConfigPostProcessor : EnvironmentPostProcessor {
4343
var logger: DeferredLog = DeferredLog()
4444

4545
companion object {
46-
val PROP = "spring.autoconfigure.exclude"
46+
const val PROP = "spring.autoconfigure.exclude"
4747
}
4848

4949
override fun postProcessEnvironment(env: ConfigurableEnvironment, application: SpringApplication) {

src/main/kotlin/ch/derlin/bbdata/common/cassandra/CTypeResolver.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ annotation class CType
2727
@Component
2828
class ContentTypeHandlerMethodArgumentResolver : HandlerMethodArgumentResolver {
2929
override fun supportsParameter(methodParameter: MethodParameter): Boolean {
30-
return methodParameter.getParameterType().equals(String::class.java) &&
30+
return methodParameter.parameterType == String::class.java &&
3131
methodParameter.hasParameterAnnotation(CType::class.java)
3232
}
3333

src/main/kotlin/ch/derlin/bbdata/common/cassandra/CassandraUtils.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ch.derlin.bbdata.common.cassandra
22

33
import org.joda.time.YearMonth
4+
import org.joda.time.format.DateTimeFormatter
45

56
/**
67
* date: 19.12.19
@@ -9,17 +10,17 @@ import org.joda.time.YearMonth
910

1011

1112
object CassandraUtils {
12-
val YM_FORMAT = org.joda.time.format.DateTimeFormat.forPattern("yyyy-MM")
13+
val YM_FORMAT: DateTimeFormatter = org.joda.time.format.DateTimeFormat.forPattern("yyyy-MM")
1314

1415
fun xMonthsFrom(d1: YearMonth, x: Int): List<String> {
1516
val ym = YearMonth(d1)
1617
return monthsBetween(ym.minusMonths(x), ym)
1718
}
1819

19-
fun monthsBetween(d1: YearMonth, d2: YearMonth? = null): List<String> {
20+
fun monthsBetween(d1: YearMonth, optionalD2: YearMonth? = null): List<String> {
2021
val months = mutableListOf<String>()
21-
var d2 = d2 ?: YearMonth.now()
22-
while (d1.compareTo(d2) <= 0) {
22+
var d2 = optionalD2 ?: YearMonth.now()
23+
while (d1 <= d2) {
2324
months.add(YM_FORMAT.print(d2))
2425
d2 = d2.minusMonths(1)
2526
}

src/main/kotlin/ch/derlin/bbdata/common/dates/DurationParser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object DurationParser {
2424
/**
2525
* Parse a duration string.
2626
*
27-
* @param periodString the duration string
27+
* @param durationString the duration string
2828
* @return the period object, or a zero period if the parsing failed.
2929
*/
3030
fun parse(durationString: String): MutablePeriod {

src/main/kotlin/ch/derlin/bbdata/common/dates/JodaUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import java.util.*
1515
*/
1616
object JodaUtils {
1717

18-
val FMT_ISO_MINUTES = "yyyy-MM-dd'T'HH:mm'Z'"
19-
val FMT_ISO_SECONDS = "yyyy-MM-dd'T'HH:mm:ss'Z'"
20-
val FMT_ISO_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
18+
const val FMT_ISO_MINUTES = "yyyy-MM-dd'T'HH:mm'Z'"
19+
const val FMT_ISO_SECONDS = "yyyy-MM-dd'T'HH:mm:ss'Z'"
20+
const val FMT_ISO_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
2121

2222
var defaultPattern: String = FMT_ISO_MILLIS
2323
set(value) {

src/main/kotlin/ch/derlin/bbdata/common/exceptions/ExceptionAdviser.kt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class ErrorAttributes : DefaultErrorAttributes() {
4343
override fun getErrorAttributes(webRequest: WebRequest, includeStackTrace: Boolean): Map<String, Any?> {
4444
val attrs = super.getErrorAttributes(webRequest, false)
4545
return mapOf(
46-
"exception" to attrs.get("error"),
47-
"details" to attrs.get("message"))
46+
"exception" to attrs["error"],
47+
"details" to attrs["message"])
4848
}
4949
}
5050

@@ -99,20 +99,23 @@ class GlobalControllerExceptionHandler : ResponseEntityExceptionHandler() {
9999

100100
fun List<ObjectError>.body(): ExceptionBody = ExceptionBody(
101101
exception = WrongParamsException::class.simpleName.toString(),
102-
details = this.associateBy({ (it as FieldError).getField() }, { it.defaultMessage })
102+
details = this.associateBy({ (it as FieldError).field }, { it.defaultMessage })
103103
)
104104

105105
fun DataIntegrityViolationException.body(): ExceptionBody =
106106
(this.cause as? ConstraintViolationException)?.sqlException?.let {
107107
val sqlMsg = it.message ?: ""
108-
val (name, msg) =
109-
if ("foreign key constraint fails" in sqlMsg) {
110-
"ForeignKeyException" to "A field references a non-existing resource."
111-
} else if ("Duplicate entry" in sqlMsg) {
112-
"DuplicateFieldException" to "value ${sqlMsg.split(" ")[2]} already exists."
113-
} else {
114-
"SqlException" to sqlMsg
115-
}
108+
val (name, msg) = when {
109+
"foreign key constraint fails" in sqlMsg -> {
110+
"ForeignKeyException" to "A field references a non-existing resource."
111+
}
112+
"Duplicate entry" in sqlMsg -> {
113+
"DuplicateFieldException" to "value ${sqlMsg.split(" ")[2]} already exists."
114+
}
115+
else -> {
116+
"SqlException" to sqlMsg
117+
}
118+
}
116119
ExceptionBody(name, msg)
117120
} ?: ExceptionBody.fromThrowable(this)
118121
}

src/main/kotlin/ch/derlin/bbdata/common/exceptions/Exceptions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ open class AppException(val details: Any) : Throwable() {
1111

1212

1313
class ItemNotFoundException(itemName: String = "resource", msg: String? = null) :
14-
AppException(msg ?: "The ${itemName} was not found or can't be accessed with this apikey.")
14+
AppException(msg ?: "The $itemName was not found or can't be accessed with this apikey.")
1515

1616
class UnauthorizedException(msg: String = "This resource is protected.") :
1717
AppException(msg)

src/main/kotlin/ch/derlin/bbdata/common/stats/SqlStats.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import javax.persistence.Column
88
import javax.persistence.Entity
99
import javax.persistence.Id
1010
import javax.persistence.Table
11+
import kotlin.math.abs
1112

1213
/**
1314
* date: 25.05.20
@@ -37,7 +38,7 @@ data class SqlStats(
3738
) {
3839
fun updateWithNewValue(v: NewValue) {
3940
if (nWrites > 0L) {
40-
val deltaMs = Math.abs(v.timestamp!!.millis - lastTs!!.millis)
41+
val deltaMs = abs(v.timestamp!!.millis - lastTs!!.millis)
4142
avgSamplePeriod = (avgSamplePeriod * (nWrites - 1) + deltaMs) / nWrites
4243
}
4344

0 commit comments

Comments
 (0)