kschlesselmann
06/30/2017, 8:07 AM@Embeddable
data class RouterId(val routerId: String) {
init {
val octets = routerId.split(":")
if (octets.size != 6) {
throw IllegalArgumentException("$routerId does not consist of 6 octets")
}
for (octet in octets) {
Integer.parseInt(octet, 16)
}
}
override fun toString(): String {
return routerId
}
}
which now fails with
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.text.StringsKt__StringsKt.split, parameter $receiver
at kotlin.text.StringsKt__StringsKt.split(Strings.kt) ~[kotlin-stdlib-1.1.3.jar:1.1.3]
at kotlin.text.StringsKt__StringsKt.split$default(Strings.kt:1153) ~[kotlin-stdlib-1.1.3.jar:1.1.3]
at domain.model.aircraft.RouterId.<init>(RouterId.kt:9) ~[main/:na]
....
during creation with JPA. In my build.gradle
I use
plugins {
id "org.jetbrains.kotlin.jvm" version "1.1.3"
id "org.jetbrains.kotlin.plugin.noarg" version "1.1.3"
id "org.jetbrains.kotlin.plugin.jpa" version "1.1.3"
id "org.springframework.boot" version "1.5.4.RELEASE"
}
any suggestions? The code runs fine using 1.1.2
.Czar
06/30/2017, 8:30 AMinit {}
which works with a constructor parameter. JPA will call no-arg constructor, then your init will run and will find a routerId == null
.kschlesselmann
06/30/2017, 8:53 AMlovis
06/30/2017, 9:15 AMrouterId
optional or provide a default value like 0:0:0:0:0:0
kschlesselmann
06/30/2017, 12:46 PMlovis
06/30/2017, 12:49 PMlovis
06/30/2017, 12:49 PMlovis
06/30/2017, 12:53 PMrouterId
? you could even add a method isValid
or something that checks for that particular onelovis
06/30/2017, 12:55 PMkschlesselmann
06/30/2017, 1:06 PMlovis
06/30/2017, 1:18 PMequals
implementation that makes it behave like a value object would.
however, I’m being pedantic here, sorry 😉lovis
06/30/2017, 1:20 PM0:0:0:0:0:0
seems like a valid state for the object itselfkschlesselmann
06/30/2017, 1:21 PMkschlesselmann
06/30/2017, 1:22 PMlovis
06/30/2017, 1:24 PMkschlesselmann
06/30/2017, 1:29 PM