java version:11 kotlin version:1.3.41 springboot version: 2.1.6.RELEASE spring version: 5.1.8.RELEASE
Success when validate params in controller, throw UninitializedPropertyAccessException
when validate entity classes before persistent data by jpa.
Use java also throws NPE.
/**用户名的校验器。*/
open class UsernameValidator : ConstraintValidator<Username, String> {
@Autowired private lateinit var validationProperties: ValidationProperties
override fun isValid(value: String, context: ConstraintValidatorContext): Boolean {
//6~16位的字母、数字和下划线。
return value.matches(validationProperties.username.toRegex())
}
}
//No problems in Controller
//Service
override fun registerByEmail(form: EmailRegisterForm): User {
val savedUser = User(
nickname = form.nickname,
username = form.username,
email = form.email,
password = passwordEncoder.encode(form.password)
)
savedUser.activateCode = UUID.randomUUID().toString()
//throws `UninitializedPropertyAccessException` Here!!!
return userRepository.save(savedUser)
}
IU-191.8026.42, JRE 11.0.2 9-b159.64x64 JetBrains s.r.o, OS Windows 10(amd64) v10.0 , screens 1366x768
Comment From: sdeleuze
Hi, sorry for the delay. Could you please provide a reproducer?
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.