From 83510424690e973713018fc26d5f0cf9dedc534e Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 19 Sep 2017 15:02:08 +0200 Subject: [PATCH] Polish "Fix handling of empty/null arguments" Closes gh-9916 --- .../springframework/boot/maven/RunArguments.java | 5 ++--- .../boot/maven/RunArgumentsTests.java | 13 ++++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunArguments.java b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunArguments.java index ed2d40d4fc8..e08b6881af2 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunArguments.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RunArguments.java @@ -18,11 +18,10 @@ package org.springframework.boot.maven; import java.util.Arrays; import java.util.LinkedList; +import java.util.Objects; import org.codehaus.plexus.util.cli.CommandLineUtils; -import org.springframework.util.StringUtils; - /** * Parse and expose arguments specified in a single string. * @@ -41,7 +40,7 @@ class RunArguments { RunArguments(String[] args) { if (args != null) { - Arrays.stream(args).filter(StringUtils::hasLength).forEach(this.args::add); + Arrays.stream(args).filter(Objects::nonNull).forEach(this.args::add); } } diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/RunArgumentsTests.java b/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/RunArgumentsTests.java index e2184f0a9cc..00f797baef1 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/RunArgumentsTests.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/RunArgumentsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,9 +43,16 @@ public class RunArgumentsTests { @Test public void parseArrayContainingNullValue() { - String[] args = new RunArguments(new String[]{null}).asArray(); + String[] args = new RunArguments(new String[]{"foo", null, "bar"}).asArray(); assertThat(args).isNotNull(); - assertThat(args.length).isEqualTo(0); + assertThat(args).containsOnly("foo", "bar"); + } + + @Test + public void parseArrayContainingEmptyValue() { + String[] args = new RunArguments(new String[]{"foo", "", "bar"}).asArray(); + assertThat(args).isNotNull(); + assertThat(args).containsOnly("foo", "", "bar"); } @Test