Tolerate null startTime

This commit prevents a potential NPE if the startTime of the
MavenSession is not available and fallbacks to the current time. This
can happen when invoking the plugin with Maven embedded in an IDE.

Closes gh-17810
This commit is contained in:
Stephane Nicoll 2019-08-08 17:32:04 +02:00
parent b8a1043e98
commit 07cd67a3fe
1 changed files with 3 additions and 1 deletions

View File

@ -18,6 +18,7 @@ package org.springframework.boot.maven;
import java.io.File;
import java.time.Instant;
import java.util.Date;
import java.util.Map;
import org.apache.maven.execution.MavenSession;
@ -100,7 +101,8 @@ public class BuildInfoMojo extends AbstractMojo {
private Instant getBuildTime() {
if (this.time == null || this.time.isEmpty()) {
return this.session.getRequest().getStartTime().toInstant();
Date startTime = this.session.getRequest().getStartTime();
return (startTime != null) ? startTime.toInstant() : Instant.now();
}
if ("off".equalsIgnoreCase(this.time)) {
return null;