From eef84c37c3514200fe915633dfe26379af6ecf06 Mon Sep 17 00:00:00 2001 From: nsingh Date: Wed, 18 Jan 2017 15:48:31 -0800 Subject: [PATCH] Handle case where text is blank in the enum parser This is to avoid calling the hints provider when it is not necessary and to better handle the case when no text is present (error should be thrown) --- .../ide/vscode/commons/util/EnumValueParser.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/EnumValueParser.java b/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/EnumValueParser.java index e53c11ca3..c54a3761c 100644 --- a/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/EnumValueParser.java +++ b/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/EnumValueParser.java @@ -41,6 +41,12 @@ public class EnumValueParser implements ValueParser { } public Object parse(String str) { + // IMPORTANT: check the text FIRST before fetching values + // from the hints provider, as the hints provider may be expensive when resolving values + if (!StringUtil.hasText(str)) { + throw new IllegalArgumentException(createBlankTextErrorMessage()); + } + Collection values = this.values.get(); //If values is not known (null) then just assume the str is acceptable. if (values==null || values.contains(str)) { @@ -50,6 +56,10 @@ public class EnumValueParser implements ValueParser { } } + protected String createBlankTextErrorMessage() { + return "'"+typeName+"'" + " cannot be blank."; + } + protected String createErrorMessage(String parseString, Collection values2) { return "'"+parseString+"' is not valid for Enum '"+typeName+"'. Valid values are: "+values; }