This is an automated email from the ASF dual-hosted git repository. mgrigorov pushed a commit to branch wicket-8.x in repository https://gitbox.apache.org/repos/asf/wicket.git
commit 50e81675dc6d75913e406c9ef6165cb302a1ac94 Author: Martin Tzvetanov Grigorov <mgrigo...@apache.org> AuthorDate: Thu Sep 10 15:28:54 2020 +0300 WICKET-6829 Use String.isEmpty() instead of "".equals(...) (cherry picked from commit 76778a2bbd882b7f988e56973944e4e2238431df) --- .../java/org/apache/wicket/ConverterLocator.java | 4 ++-- .../markup/html/form/AbstractSingleSelectChoice.java | 4 ++-- .../wicket/markup/html/image/ExternalImage.java | 2 +- .../org/apache/wicket/markup/html/image/Image.java | 2 +- .../wicket/markup/html/basic/SimplePageTest.java | 13 +++++++------ .../apache/wicket/examples/wizard/NewUserWizard.java | 5 +++-- .../ajax/markup/html/AjaxEditableLabel.java | 5 +---- .../ajax/markup/html/AjaxEditableMultiLineLabel.java | 5 +---- .../src/main/java/org/apache/wicket/request/Url.java | 20 +++++++++++--------- .../java/org/apache/wicket/request/UrlRenderer.java | 2 +- .../wicket/util/resource/ZipResourceStream.java | 8 +++----- .../java/org/apache/wicket/util/string/Strings.java | 4 ++-- 12 files changed, 35 insertions(+), 39 deletions(-) diff --git a/wicket-core/src/main/java/org/apache/wicket/ConverterLocator.java b/wicket-core/src/main/java/org/apache/wicket/ConverterLocator.java index dbef956..9b8def9 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ConverterLocator.java +++ b/wicket-core/src/main/java/org/apache/wicket/ConverterLocator.java @@ -96,7 +96,7 @@ public class ConverterLocator implements IConverterLocator return null; } Class<C> theType = type.get(); - if ("".equals(value)) + if (value.isEmpty()) { if (String.class.equals(theType)) { @@ -130,7 +130,7 @@ public class ConverterLocator implements IConverterLocator @Override public String convertToString(C value, Locale locale) { - if (value == null || "".equals(value)) + if (value == null || (value instanceof String && ((String) value).isEmpty())) { return ""; } diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractSingleSelectChoice.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractSingleSelectChoice.java index 3ff86d0..d12f6d9 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractSingleSelectChoice.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/form/AbstractSingleSelectChoice.java @@ -309,7 +309,7 @@ public abstract class AbstractSingleSelectChoice<T> extends AbstractChoice<T, T> buffer.append("\n<option"); // If null is selected, indicate that - if ("".equals(selectedValue)) + if (selectedValue != null && selectedValue.isEmpty()) { buffer.append(" selected=\"selected\""); } @@ -321,7 +321,7 @@ public abstract class AbstractSingleSelectChoice<T> extends AbstractChoice<T, T> else { // Null is not valid. Is it selected anyway? - if ("".equals(selectedValue)) + if (selectedValue != null && selectedValue.isEmpty()) { // Force the user to pick a non-null value String option = getNullKeyDisplayValue(); diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/ExternalImage.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/ExternalImage.java index 2a30418..81858ac 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/ExternalImage.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/ExternalImage.java @@ -217,7 +217,7 @@ public class ExternalImage extends WebComponent { sizes = sizes.substring(0, lastIndexOf); } - if (!"".equals(sizes)) + if (!sizes.isEmpty()) { tag.put("sizes", sizes); } diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image.java index 60677d1..a75787c 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image.java @@ -523,7 +523,7 @@ public class Image extends WebComponent implements IRequestListener { sizes = sizes.substring(0, lastIndexOf); } - if (!"".equals(sizes)) + if (!sizes.isEmpty()) { tag.put("sizes", sizes); } diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java index 8e8de92..4a1614e 100644 --- a/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/SimplePageTest.java @@ -62,33 +62,34 @@ public class SimplePageTest extends WicketTestCase label = (Label)tester.getLastRenderedPage().get("myPanel:label"); assertNotNull(label); - assertFalse("".equals(document)); + assertNotEquals("", document); assertTrue(document.contains("<span wicket:id=\"label\">mein Label</span>")); Border border = (Border)tester.getLastRenderedPage().get("myBorder"); assertNotNull(border); - assertFalse("".equals(document)); + assertNotEquals("", document); assertTrue(document.contains("<wicket:border>before body - <wicket:body>border</wicket:body> - after body</wicket:border>")); border = (Border)tester.getLastRenderedPage().get("myBorder2"); assertNotNull(border); - assertFalse("".equals(document)); + assertNotEquals("", document); assertTrue(document.contains("<span wicket:id=\"myBorder2\" testAttr=\"myValue\"><wicket:border>before body - <wicket:body>border</wicket:body> - after body</wicket:border></span>")); // do the same test twice. Igor reported a problem with that, so we have to test it. border = (Border)tester.getLastRenderedPage().get("myBorder2"); assertNotNull(border); - assertFalse("".equals(document)); + + assertNotEquals("", document); assertTrue(document.contains("<span wicket:id=\"myBorder2\" testAttr=\"myValue\"><wicket:border>before body - <wicket:body>border</wicket:body> - after body</wicket:border></span>")); WebMarkupContainer container = (WebMarkupContainer)tester.getLastRenderedPage().get("test"); assertNotNull(container); - assertFalse("".equals(document)); + assertNotEquals("", document); assertTrue(document.contains("body<span wicket:id=\"myLabel2\">Test Label2</span>")); label = (Label)tester.getLastRenderedPage().get("test:myLabel2"); assertNotNull(label); - assertFalse("".equals(document)); + assertNotEquals("", document); assertTrue(document.contains("<span wicket:id=\"myLabel2\">Test Label2</span>")); } diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/wizard/NewUserWizard.java b/wicket-examples/src/main/java/org/apache/wicket/examples/wizard/NewUserWizard.java index 17d234b..1129eeb 100644 --- a/wicket-examples/src/main/java/org/apache/wicket/examples/wizard/NewUserWizard.java +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/wizard/NewUserWizard.java @@ -150,9 +150,10 @@ public class NewUserWizard extends Wizard public void validate(Form<?> form) { String rolesInput = rolesChoiceField.getInput(); - if (rolesInput != null && (!"".equals(rolesInput))) + if (rolesInput != null && !rolesInput.isEmpty()) { - if ("".equals(rolesSetNameField.getInput())) + final String rolesSetNameFieldInput = rolesSetNameField.getInput(); + if (rolesSetNameFieldInput == null || rolesSetNameFieldInput.isEmpty()) { rolesSetNameField.error(new ValidationError().addKey("error.noSetNameForRoles")); } diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableLabel.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableLabel.java index ffe5890..81b8436 100644 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableLabel.java +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableLabel.java @@ -401,15 +401,12 @@ public class AjaxEditableLabel<T> extends Panel implements IGenericComponent<T, return c != null ? c : super.getConverter(type); } - /** - * {@inheritDoc} - */ @Override public void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { Object modelObject = getDefaultModelObject(); - if ((modelObject == null) || "".equals(modelObject)) + if ((modelObject == null) || (modelObject instanceof String && ((String) modelObject).isEmpty())) { replaceComponentTagBody(markupStream, openTag, defaultNullLabel()); } diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableMultiLineLabel.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableMultiLineLabel.java index bd95b02..712bc31 100644 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableMultiLineLabel.java +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableMultiLineLabel.java @@ -86,15 +86,12 @@ public class AjaxEditableMultiLineLabel<T> extends AjaxEditableLabel<T> { private static final long serialVersionUID = 1L; - /** - * {@inheritDoc} - */ @Override public void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) { Object modelObject = getDefaultModelObject(); - if ((modelObject == null) || "".equals(modelObject)) + if ((modelObject == null) || (modelObject instanceof String && ((String) modelObject).isEmpty())) { replaceComponentTagBody(markupStream, openTag, defaultNullLabel()); } diff --git a/wicket-request/src/main/java/org/apache/wicket/request/Url.java b/wicket-request/src/main/java/org/apache/wicket/request/Url.java index be52c5b..a056a22 100755 --- a/wicket-request/src/main/java/org/apache/wicket/request/Url.java +++ b/wicket-request/src/main/java/org/apache/wicket/request/Url.java @@ -1055,19 +1055,21 @@ public class Url implements Serializable // remove leading './' (current folder) and empty segments, process any ../ segments from // the relative url - while (!relative.getSegments().isEmpty()) + final List<String> relativeSegments = relative.getSegments(); + while (!relativeSegments.isEmpty()) { - if (".".equals(relative.getSegments().get(0))) + final String firstSegment = relativeSegments.get(0); + if (".".equals(firstSegment)) { - relative.getSegments().remove(0); + relativeSegments.remove(0); } - else if ("".equals(relative.getSegments().get(0))) + else if (firstSegment.isEmpty()) { - relative.getSegments().remove(0); + relativeSegments.remove(0); } - else if ("..".equals(relative.getSegments().get(0))) + else if ("..".equals(firstSegment)) { - relative.getSegments().remove(0); + relativeSegments.remove(0); if (getSegments().isEmpty() == false) { getSegments().remove(getSegments().size() - 1); @@ -1079,13 +1081,13 @@ public class Url implements Serializable } } - if (!getSegments().isEmpty() && relative.getSegments().isEmpty()) + if (!getSegments().isEmpty() && relativeSegments.isEmpty()) { getSegments().add(""); } // append the remaining relative segments - getSegments().addAll(relative.getSegments()); + getSegments().addAll(relativeSegments); // replace query params with the ones from relative parameters.clear(); diff --git a/wicket-request/src/main/java/org/apache/wicket/request/UrlRenderer.java b/wicket-request/src/main/java/org/apache/wicket/request/UrlRenderer.java index f4d8720..c02996a 100644 --- a/wicket-request/src/main/java/org/apache/wicket/request/UrlRenderer.java +++ b/wicket-request/src/main/java/org/apache/wicket/request/UrlRenderer.java @@ -322,7 +322,7 @@ public class UrlRenderer { // try to remove context/filter path only if the Url starts with '/', // i.e. has an empty segment in the beginning - if (segments.isEmpty() || "".equals(segments.get(0)) == false) + if ((segments.isEmpty() || segments.get(0).isEmpty()) == false) { return; } diff --git a/wicket-util/src/main/java/org/apache/wicket/util/resource/ZipResourceStream.java b/wicket-util/src/main/java/org/apache/wicket/util/resource/ZipResourceStream.java index 270dd67..4d0f7f9 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/resource/ZipResourceStream.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/resource/ZipResourceStream.java @@ -136,10 +136,8 @@ public class ZipResourceStream extends AbstractResourceStream { for (String file : files) { - if (log.isDebugEnabled()) - { - log.debug("Adding: '{}'", file); - } + log.debug("Adding: '{}'", file); + File f = new File(dir, file); if (f.isDirectory()) { @@ -169,7 +167,7 @@ public class ZipResourceStream extends AbstractResourceStream } } - if ("".equals(path)) + if (path.isEmpty()) { out.close(); } diff --git a/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java b/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java index bb06622..5efb6bf 100755 --- a/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java @@ -768,7 +768,7 @@ public final class Strings // If searchFor is null or the empty string, then there is nothing to // replace, so returning s is the only option here. - if ((searchFor == null) || "".equals(searchFor)) + if ((searchFor == null) || searchFor.length() == 0) { return s; } @@ -875,7 +875,7 @@ public final class Strings // Stripping a null or empty string from the end returns the // original string. - if ((ending == null) || "".equals(ending)) + if (ending == null || ending.isEmpty()) { return s; }