From 07cd67a3fe6326144443e875449bf38a5e583216 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 8 Aug 2019 17:32:04 +0200 Subject: [PATCH] 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 --- .../java/org/springframework/boot/maven/BuildInfoMojo.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java index ea371714b2..ea6d9d16b6 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java @@ -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;