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) { if (source != null) {
try { try {
org.apache.maven.api.model.InputSource v4src = org.apache.maven.api.model.InputLocation loc = model.getLocation("");
model.getLocation("").getSource(); org.apache.maven.api.model.InputSource v4src = loc != null ? loc.getSource() : null;
Field field = InputSource.class.getDeclaredField("modelId"); if (v4src != null) {
field.setAccessible(true); Field field = InputSource.class.getDeclaredField("modelId");
field.set(v4src, ModelProblemUtils.toId(model)); field.setAccessible(true);
field.set(v4src, ModelProblemUtils.toId(model));
}
} catch (Throwable t) { } catch (Throwable t) {
// TODO: use a lazy source ? // TODO: use a lazy source ?
throw new IllegalStateException("Unable to set modelId on InputSource", t); throw new IllegalStateException("Unable to set modelId on InputSource", t);