Add a null default to @Value on nullable fields and parameters

Proprietary

Rewrites Spring's @Value("${some.property}") to @Value("${some.property:#{null}}") on a field of a class or a method parameter that carries a nullable annotation, and on a setter whose parameter carries one. This changes startup behavior on purpose: a missing property now injects null instead of failing bean creation, which is what the nullable annotation already declares. Only a value holding exactly one placeholder without a default is rewritten. It may be a string literal, kept with its escape sequences, or a reference to a constant that a source file of the repository initializes with a string literal without escape sequences; the reference is replaced by the literal with the default and the constant is left unchanged. A text block, a concatenation, a constant declared outside the repository, a value with whitespace or other text around the placeholder, more than one placeholder or a SpEL expression, and an empty placeholder are left alone. So are a constructor parameter, a primitive, which cannot hold null, an array whose nullable annotation is a type annotation such as JSpecify's, a nullable annotation written inside the type as in java.lang.@Nullable String, a setter whose parameter has its own @Value, a @Value written after a method's type parameters, which Sonar does not read, and an annotation that only inherits nullability from a meta-annotation. Test sources are not changed.

io.moderne.java.spring.framework.AddNullDefaultToNullableValue
mod run . --recipe=io.moderne.java.spring.framework.AddNullDefaultToNullableValue

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.