Skip to content

Commit 2e02c79

Browse files
Merge pull request #203 from SpineEventEngine/check-for-null
Propagate `@Nullable` annotation to the generated code and add a precondition check
2 parents 7fb223a + 4f39e5f commit 2e02c79

File tree

10 files changed

+121
-56
lines changed

10 files changed

+121
-56
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ allprojects {
9292
Roaster.api,
9393
Roaster.jdt,
9494
ProtoData.api,
95+
ProtoData.params,
9596
ProtoData.pluginLib,
9697
ProtoData.backend,
9798
ProtoData.java,

buildSrc/src/main/kotlin/io/spine/dependency/local/ProtoData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ object ProtoData {
7373
* The version of ProtoData dependencies.
7474
*/
7575
val version: String
76-
private const val fallbackVersion = "0.93.4"
76+
private const val fallbackVersion = "0.93.5"
7777

7878
/**
7979
* The distinct version of ProtoData used by other build tools.

dependencies.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
# Dependencies of `io.spine.validation:spine-validation-java:2.0.0-SNAPSHOT.304`
3+
# Dependencies of `io.spine.validation:spine-validation-java:2.0.0-SNAPSHOT.305`
44

55
## Runtime
66
1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.3.
@@ -861,12 +861,12 @@
861861

862862
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
863863

864-
This report was generated on **Tue Mar 25 18:25:23 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
864+
This report was generated on **Wed Mar 26 11:24:52 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
865865

866866

867867

868868

869-
# Dependencies of `io.spine.validation:spine-validation-java-bundle:2.0.0-SNAPSHOT.304`
869+
# Dependencies of `io.spine.validation:spine-validation-java-bundle:2.0.0-SNAPSHOT.305`
870870

871871
## Runtime
872872
1. **Group** : org.jetbrains. **Name** : annotations. **Version** : 26.0.2.
@@ -1466,12 +1466,12 @@ This report was generated on **Tue Mar 25 18:25:23 CET 2025** using [Gradle-Lice
14661466

14671467
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
14681468

1469-
This report was generated on **Tue Mar 25 18:25:24 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
1469+
This report was generated on **Wed Mar 26 11:24:52 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
14701470

14711471

14721472

14731473

1474-
# Dependencies of `io.spine.validation:spine-validation-java-runtime:2.0.0-SNAPSHOT.304`
1474+
# Dependencies of `io.spine.validation:spine-validation-java-runtime:2.0.0-SNAPSHOT.305`
14751475

14761476
## Runtime
14771477
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
@@ -2154,12 +2154,12 @@ This report was generated on **Tue Mar 25 18:25:24 CET 2025** using [Gradle-Lice
21542154

21552155
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
21562156

2157-
This report was generated on **Tue Mar 25 18:25:24 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
2157+
This report was generated on **Wed Mar 26 11:24:53 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
21582158

21592159

21602160

21612161

2162-
# Dependencies of `io.spine.validation:spine-validation-java-tests:2.0.0-SNAPSHOT.304`
2162+
# Dependencies of `io.spine.validation:spine-validation-java-tests:2.0.0-SNAPSHOT.305`
21632163

21642164
## Runtime
21652165
1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.3.
@@ -3128,12 +3128,12 @@ This report was generated on **Tue Mar 25 18:25:24 CET 2025** using [Gradle-Lice
31283128

31293129
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
31303130

3131-
This report was generated on **Tue Mar 25 18:25:24 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
3131+
This report was generated on **Wed Mar 26 11:24:53 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
31323132

31333133

31343134

31353135

3136-
# Dependencies of `io.spine.validation:spine-validation-model:2.0.0-SNAPSHOT.304`
3136+
# Dependencies of `io.spine.validation:spine-validation-model:2.0.0-SNAPSHOT.305`
31373137

31383138
## Runtime
31393139
1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.3.
@@ -4018,12 +4018,12 @@ This report was generated on **Tue Mar 25 18:25:24 CET 2025** using [Gradle-Lice
40184018

40194019
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
40204020

4021-
This report was generated on **Tue Mar 25 18:25:25 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
4021+
This report was generated on **Wed Mar 26 11:24:53 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
40224022

40234023

40244024

40254025

4026-
# Dependencies of `io.spine.validation:spine-validation-proto:2.0.0-SNAPSHOT.304`
4026+
# Dependencies of `io.spine.validation:spine-validation-proto:2.0.0-SNAPSHOT.305`
40274027

40284028
## Runtime
40294029
1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.3.
@@ -4972,12 +4972,12 @@ This report was generated on **Tue Mar 25 18:25:25 CET 2025** using [Gradle-Lice
49724972

49734973
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
49744974

4975-
This report was generated on **Tue Mar 25 18:25:25 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
4975+
This report was generated on **Wed Mar 26 11:24:54 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
49764976

49774977

49784978

49794979

4980-
# Dependencies of `io.spine.validation:spine-validation-consumer:2.0.0-SNAPSHOT.304`
4980+
# Dependencies of `io.spine.validation:spine-validation-consumer:2.0.0-SNAPSHOT.305`
49814981

49824982
## Runtime
49834983
1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.3.
@@ -5862,12 +5862,12 @@ This report was generated on **Tue Mar 25 18:25:25 CET 2025** using [Gradle-Lice
58625862

58635863
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
58645864

5865-
This report was generated on **Tue Mar 25 18:25:25 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
5865+
This report was generated on **Wed Mar 26 11:24:54 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
58665866

58675867

58685868

58695869

5870-
# Dependencies of `io.spine.validation:spine-validation-consumer-dependency:2.0.0-SNAPSHOT.304`
5870+
# Dependencies of `io.spine.validation:spine-validation-consumer-dependency:2.0.0-SNAPSHOT.305`
58715871

58725872
## Runtime
58735873
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
@@ -6679,12 +6679,12 @@ This report was generated on **Tue Mar 25 18:25:25 CET 2025** using [Gradle-Lice
66796679

66806680
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
66816681

6682-
This report was generated on **Tue Mar 25 18:25:25 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
6682+
This report was generated on **Wed Mar 26 11:24:54 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
66836683

66846684

66856685

66866686

6687-
# Dependencies of `io.spine.validation:spine-validation-extensions:2.0.0-SNAPSHOT.304`
6687+
# Dependencies of `io.spine.validation:spine-validation-extensions:2.0.0-SNAPSHOT.305`
66886688

66896689
## Runtime
66906690
1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.3.
@@ -7617,12 +7617,12 @@ This report was generated on **Tue Mar 25 18:25:25 CET 2025** using [Gradle-Lice
76177617

76187618
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
76197619

7620-
This report was generated on **Tue Mar 25 18:25:26 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
7620+
This report was generated on **Wed Mar 26 11:24:54 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
76217621

76227622

76237623

76247624

7625-
# Dependencies of `io.spine.validation:spine-validation-runtime:2.0.0-SNAPSHOT.304`
7625+
# Dependencies of `io.spine.validation:spine-validation-runtime:2.0.0-SNAPSHOT.305`
76267626

76277627
## Runtime
76287628
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
@@ -8450,12 +8450,12 @@ This report was generated on **Tue Mar 25 18:25:26 CET 2025** using [Gradle-Lice
84508450

84518451
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
84528452

8453-
This report was generated on **Tue Mar 25 18:25:26 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
8453+
This report was generated on **Wed Mar 26 11:24:55 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
84548454

84558455

84568456

84578457

8458-
# Dependencies of `io.spine.validation:spine-validation-validating:2.0.0-SNAPSHOT.304`
8458+
# Dependencies of `io.spine.validation:spine-validation-validating:2.0.0-SNAPSHOT.305`
84598459

84608460
## Runtime
84618461
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
@@ -9287,12 +9287,12 @@ This report was generated on **Tue Mar 25 18:25:26 CET 2025** using [Gradle-Lice
92879287

92889288
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
92899289

9290-
This report was generated on **Tue Mar 25 18:25:26 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
9290+
This report was generated on **Wed Mar 26 11:24:55 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
92919291

92929292

92939293

92949294

9295-
# Dependencies of `io.spine.validation:spine-validation-vanilla:2.0.0-SNAPSHOT.304`
9295+
# Dependencies of `io.spine.validation:spine-validation-vanilla:2.0.0-SNAPSHOT.305`
92969296

92979297
## Runtime
92989298
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
@@ -10056,12 +10056,12 @@ This report was generated on **Tue Mar 25 18:25:26 CET 2025** using [Gradle-Lice
1005610056

1005710057
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
1005810058

10059-
This report was generated on **Tue Mar 25 18:25:26 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
10059+
This report was generated on **Wed Mar 26 11:24:55 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
1006010060

1006110061

1006210062

1006310063

10064-
# Dependencies of `io.spine.validation:spine-validation-configuration:2.0.0-SNAPSHOT.304`
10064+
# Dependencies of `io.spine.validation:spine-validation-configuration:2.0.0-SNAPSHOT.305`
1006510065

1006610066
## Runtime
1006710067
1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.3.
@@ -10994,12 +10994,12 @@ This report was generated on **Tue Mar 25 18:25:26 CET 2025** using [Gradle-Lice
1099410994

1099510995
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
1099610996

10997-
This report was generated on **Tue Mar 25 18:25:26 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
10997+
This report was generated on **Wed Mar 26 11:24:55 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
1099810998

1099910999

1100011000

1100111001

11002-
# Dependencies of `io.spine.validation:spine-validation-context:2.0.0-SNAPSHOT.304`
11002+
# Dependencies of `io.spine.validation:spine-validation-context:2.0.0-SNAPSHOT.305`
1100311003

1100411004
## Runtime
1100511005
1. **Group** : com.fasterxml.jackson. **Name** : jackson-bom. **Version** : 2.15.3.
@@ -11932,4 +11932,4 @@ This report was generated on **Tue Mar 25 18:25:26 CET 2025** using [Gradle-Lice
1193211932

1193311933
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
1193411934

11935-
This report was generated on **Tue Mar 25 18:25:27 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
11935+
This report was generated on **Wed Mar 26 11:24:55 CET 2025** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).

java-tests/validating/src/test/kotlin/io/spine/test/JavaMessageSmokeTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ import com.google.protobuf.Message
3030
import io.kotest.matchers.collections.shouldContain
3131
import io.kotest.matchers.collections.shouldNotBeEmpty
3232
import io.kotest.matchers.shouldNotBe
33+
import io.spine.base.FieldPath
3334
import io.spine.test.protobuf.CardNumber
35+
import io.spine.type.TypeName
3436
import io.spine.validate.NonValidated
3537
import io.spine.validate.ValidatableMessage
3638
import io.spine.validate.Validate.check
@@ -72,6 +74,16 @@ internal class JavaMessageSmokeTest {
7274
exception.constraintViolations.shouldNotBeEmpty()
7375
}
7476

77+
@Test
78+
fun `throw 'NullPointerException' if given 'null' for the parent path`() {
79+
val message = valid.build()
80+
assertThrows<NullPointerException> {
81+
// The cast prevents the Kotlin compiler warning about passing `null`
82+
// to a non-`@Nullable` Java parameter.
83+
message.validate(null as FieldPath, TypeName.of("Something"))
84+
}
85+
}
86+
7587
@Test
7688
fun `ignore invalid message when skipping validation intentionally via 'buildPartial'`() {
7789
val number: @NonValidated Message = invalid.buildPartial()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2025, TeamDev. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Redistribution and use in source and/or binary forms, with or without
11+
* modification, must retain the above copyright notice and the following
12+
* disclaimer.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
27+
package io.spine.validation.java.expression
28+
29+
import io.spine.protodata.java.AnnotatedClassName
30+
import io.spine.protodata.java.ClassName
31+
import org.checkerframework.checker.nullness.qual.Nullable
32+
33+
/**
34+
* The [ClassName] of [org.checkerframework.checker.nullness.qual.Nullable].
35+
*/
36+
internal val NullableAnnotation = ClassName(Nullable::class)
37+
38+
/**
39+
* The [TypeNameClass] annotated with [NullableAnnotation].
40+
*/
41+
internal val NullableTypeNameClass = AnnotatedClassName(TypeNameClass, NullableAnnotation)

java/src/main/kotlin/io/spine/validation/java/expression/ClassNames.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import io.spine.validate.ConstraintViolation
4444
import io.spine.validate.TemplateString
4545
import io.spine.validate.ValidatableMessage
4646
import io.spine.validate.ValidationError
47+
import java.util.*
4748
import java.util.regex.Pattern
4849
import java.util.stream.Collectors
4950

@@ -149,9 +150,14 @@ internal val TypeNameClass = ClassName(TypeName::class)
149150
/**
150151
* The [ClassName] of [java.lang.Integer].
151152
*/
152-
internal val IntegerClassName = ClassName(Integer::class)
153+
internal val IntegerClass = ClassName(Integer::class)
153154

154155
/**
155156
* The [ClassName] of [java.lang.Long].
156157
*/
157-
internal val LongClassName = ClassName(java.lang.Long::class)
158+
internal val LongClass = ClassName(java.lang.Long::class)
159+
160+
/**
161+
* The [ClassName] of [java.util.Objects].
162+
*/
163+
internal val ObjectsClass = ClassName(Objects::class)

java/src/main/kotlin/io/spine/validation/java/generate/ValidationCodeInjector.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ import io.spine.validate.Validated
5454
import io.spine.validate.ValidatingBuilder
5555
import io.spine.validation.java.generate.ValidationCodeInjector.ValidateScope.violations
5656
import io.spine.validation.java.expression.FieldPathClass
57-
import io.spine.validation.java.expression.TypeNameClass
57+
import io.spine.validation.java.expression.NullableTypeNameClass
58+
import io.spine.validation.java.expression.ObjectsClass
59+
import io.spine.validation.java.generate.ValidationCodeInjector.ValidateScope.parentName
60+
import io.spine.validation.java.generate.ValidationCodeInjector.ValidateScope.parentPath
5861

5962
/**
6063
* A [PsiClass] holding an instance of [Message].
@@ -168,7 +171,8 @@ private fun MessagePsiClass.declareDefaultValidateMethod() {
168171
private fun MessagePsiClass.declareValidateMethod(constraints: List<CodeBlock>) {
169172
val psiMethod = elementFactory.createMethodFromText(
170173
"""
171-
public java.util.Optional<io.spine.validate.ValidationError> validate($FieldPathClass parentPath, $TypeNameClass parentName) {
174+
public java.util.Optional<io.spine.validate.ValidationError> validate($FieldPathClass $parentPath, $NullableTypeNameClass $parentName) {
175+
${ObjectsClass}.requireNonNull($parentPath);
172176
${validateMethodBody(constraints)}
173177
}
174178
""".trimIndent(), this

0 commit comments

Comments
 (0)