Skip to content

Commit b102437

Browse files
authored
Fix #11127: enforce non-null keys in InputLocation lookups and complete Javadoc on master\n\n- modello templates: add Objects.requireNonNull(key, "key") in InputLocation.getLocation(Object)\n- modello templates: document non-null key requirement in InputLocationTracker and method Javadoc\n- ensure generated model code across modules reflects the contract\n\nFormatting: spotless applied. Full build to be run in CI. (#11129)
1 parent f01db87 commit b102437

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/mdo/java/InputLocation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public InputSource getSource() {
9999

100100
@Override
101101
public InputLocation getLocation(Object key) {
102+
Objects.requireNonNull(key, "key");
102103
return locations != null ? locations.get(key) : null;
103104
}
104105

src/mdo/java/InputLocationTracker.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,23 @@
1818
*/
1919
package ${package};
2020

21+
/**
22+
* Tracks input source locations for model fields.
23+
* <p>
24+
* Implementations provide a mapping from keys (typically field names or indices) to
25+
* {@link InputLocation} instances to support precise error reporting and diagnostics.
26+
* Keys must be non-null.
27+
*
28+
* @since 4.0.0
29+
*/
2130
public interface InputLocationTracker {
31+
/**
32+
* Gets the location of the specified field in the input source.
33+
*
34+
* @param field the key of the field, must not be {@code null}
35+
* @return the location of the field in the input source or {@code null} if unknown
36+
* @throws NullPointerException if {@code field} is {@code null}
37+
*/
2238
InputLocation getLocation(Object field);
2339

2440
/**

src/mdo/model.vm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,13 @@ public class ${class.name}
240240
#if ( $locationTracking && !$class.superClass )
241241
/**
242242
* Gets the location of the specified field in the input source.
243+
*
244+
* @param key the key of the field, must not be {@code null}
245+
* @return the location of the field in the input source or {@code null} if unknown
246+
* @throws NullPointerException if {@code key} is {@code null}
243247
*/
244248
public InputLocation getLocation(Object key) {
249+
Objects.requireNonNull(key, "key");
245250
return locations.get(key);
246251
}
247252

0 commit comments

Comments
 (0)