Skip to content

Commit 7426579

Browse files
committed
Improve the error message when additional build-info prop has null value
Closes gh-6724
1 parent f41e629 commit 7426579

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/BuildPropertiesWriter.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.text.SimpleDateFormat;
2323
import java.util.Date;
2424
import java.util.Map;
25+
import java.util.Map.Entry;
2526
import java.util.Properties;
2627

2728
/**
@@ -119,9 +120,21 @@ public ProjectDetails(String group, String artifact, String version, String name
119120
this.artifact = artifact;
120121
this.name = name;
121122
this.version = version;
123+
validateAdditionalProperties(additionalProperties);
122124
this.additionalProperties = additionalProperties;
123125
}
124126

127+
private static void validateAdditionalProperties(
128+
Map<String, String> additionalProperties) {
129+
if (additionalProperties != null) {
130+
for (Entry<String, String> property : additionalProperties.entrySet()) {
131+
if (property.getValue() == null) {
132+
throw new NullAdditionalPropertyValueException(property.getKey());
133+
}
134+
}
135+
}
136+
}
137+
125138
public String getGroup() {
126139
return this.group;
127140
}
@@ -143,4 +156,16 @@ public Map<String, String> getAdditionalProperties() {
143156
}
144157

145158
}
159+
160+
/**
161+
* Exception thrown when an additional property with a null value is encountered.
162+
*/
163+
public static class NullAdditionalPropertyValueException
164+
extends IllegalArgumentException {
165+
166+
public NullAdditionalPropertyValueException(String name) {
167+
super("Additional property '" + name + "' is illegal as its value is null");
168+
}
169+
170+
}
146171
}

spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildInfoMojo.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.maven.project.MavenProject;
2929

3030
import org.springframework.boot.loader.tools.BuildPropertiesWriter;
31+
import org.springframework.boot.loader.tools.BuildPropertiesWriter.NullAdditionalPropertyValueException;
3132
import org.springframework.boot.loader.tools.BuildPropertiesWriter.ProjectDetails;
3233

3334
/**
@@ -53,8 +54,8 @@ public class BuildInfoMojo extends AbstractMojo {
5354
private File outputFile;
5455

5556
/**
56-
* Additional properties to store in the build-info.properties. Each entry is prefixed by
57-
* {@code build.} in the generated build-info.properties.
57+
* Additional properties to store in the build-info.properties. Each entry is prefixed
58+
* by {@code build.} in the generated build-info.properties.
5859
*/
5960
@Parameter
6061
private Map<String, String> additionalProperties;
@@ -67,6 +68,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
6768
this.project.getArtifactId(), this.project.getVersion(),
6869
this.project.getName(), this.additionalProperties));
6970
}
71+
catch (NullAdditionalPropertyValueException ex) {
72+
throw new MojoFailureException(
73+
"Failed to generated build-info.properties. " + ex.getMessage(), ex);
74+
}
7075
catch (Exception ex) {
7176
throw new MojoExecutionException(ex.getMessage(), ex);
7277
}

0 commit comments

Comments
 (0)