Fix possible NPE

This commit is contained in:
Guillaume Nodet 2023-05-31 15:52:05 +02:00
parent ba3d3516eb
commit 26ee15a47e
1 changed files with 7 additions and 5 deletions

View File

@ -1033,11 +1033,13 @@ public class DefaultModelBuilder implements ModelBuilder {
if (source != null) {
try {
org.apache.maven.api.model.InputSource v4src =
model.getLocation("").getSource();
org.apache.maven.api.model.InputLocation loc = model.getLocation("");
org.apache.maven.api.model.InputSource v4src = loc != null ? loc.getSource() : null;
if (v4src != null) {
Field field = InputSource.class.getDeclaredField("modelId");
field.setAccessible(true);
field.set(v4src, ModelProblemUtils.toId(model));
}
} catch (Throwable t) {
// TODO: use a lazy source ?
throw new IllegalStateException("Unable to set modelId on InputSource", t);