I have the following Kotlin code using with spring, I get a NPE.
When the defaultExt
get used in the save
method, it’s a null, I don’t understand, I pass it as "png"
.
@Repository
class CoverRepository(
@Value("\${photo.location}") root: String,
) : PressBaseRepository(root, "png", "cover") {
}
@NoRepositoryBean
abstract class PressBaseRepository(
root: String,
private val defaultExt: String,
private val type: String
) : DiskRepository(root) {
fun save(id: Long, lang: Locale, cover: MultipartFile): String {
val ext = parseExt(cover, defaultExt)
val filename = "press_%s_%d_%s.%s".format(type, id, lang.toLanguageTag(), ext)
saveToRoot(filename, cover)
return filename
}
}
Error:
java.lang.NullPointerException: Parameter specified as non-null is null: method com.pagepilot.v2.repository.core.FilenameKt.parseExt, parameter default