diff --git a/cli/src/main/java/hudson/cli/CLI.java b/cli/src/main/java/hudson/cli/CLI.java index b206b407dd21..adfdbb4e0b33 100644 --- a/cli/src/main/java/hudson/cli/CLI.java +++ b/cli/src/main/java/hudson/cli/CLI.java @@ -245,9 +245,9 @@ public static int _main(String[] _args) throws Exception { if (auth == null && bearer == null) { // -auth option not set - if (StringUtils.isNotBlank(userIdEnv) && StringUtils.isNotBlank(tokenEnv)) { + if ((userIdEnv != null && !userIdEnv.isBlank()) && (tokenEnv != null && !tokenEnv.isBlank())) { auth = StringUtils.defaultString(userIdEnv).concat(":").concat(StringUtils.defaultString(tokenEnv)); - } else if (StringUtils.isNotBlank(userIdEnv) || StringUtils.isNotBlank(tokenEnv)) { + } else if ((userIdEnv != null && !userIdEnv.isBlank()) || (tokenEnv != null && !tokenEnv.isBlank())) { printUsage(Messages.CLI_BadAuth()); return -1; } // Otherwise, none credentials were set diff --git a/core/src/main/java/hudson/FilePath.java b/core/src/main/java/hudson/FilePath.java index 73a1bcc24a4d..0e44e287cffa 100644 --- a/core/src/main/java/hudson/FilePath.java +++ b/core/src/main/java/hudson/FilePath.java @@ -133,7 +133,6 @@ import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.fileupload.FileItem; import org.apache.commons.io.input.CountingInputStream; -import org.apache.commons.lang.StringUtils; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; @@ -1712,7 +1711,7 @@ public String invoke(File dir, VirtualChannel channel) throws IOException { public FilePath createTempDir(final String prefix, final String suffix) throws IOException, InterruptedException { try { String[] s; - if (StringUtils.isBlank(suffix)) { + if (suffix == null || suffix.isBlank()) { s = new String[]{prefix, "tmp"}; // see File.createTempFile - tmp is used if suffix is null } else { s = new String[]{prefix, suffix}; diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index dbf031d2461a..eb0f71fe20fa 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -968,7 +968,7 @@ public static String inferHudsonURL(StaplerRequest req) { public static String getFooterURL() { if (footerURL == null) { footerURL = SystemProperties.getString("hudson.footerURL"); - if (StringUtils.isBlank(footerURL)) { + if (footerURL == null || footerURL.isBlank()) { footerURL = "https://www.jenkins.io/"; } } @@ -2194,7 +2194,7 @@ private String getJellyViewsInformationForCurrentRequest() { int firstPeriod = part.indexOf("."); return slash > 0 && firstPeriod > 0 && slash < firstPeriod; }).collect(Collectors.joining(" ")); - if (StringUtils.isBlank(views)) { + if (views == null || views.isBlank()) { // fallback to full thread name if there are no apparent views return threadName; } diff --git a/core/src/main/java/hudson/PluginManager.java b/core/src/main/java/hudson/PluginManager.java index a7d74fcee478..39cbb3e7c961 100644 --- a/core/src/main/java/hudson/PluginManager.java +++ b/core/src/main/java/hudson/PluginManager.java @@ -272,7 +272,7 @@ PluginManager doCreate(@NonNull Class klass, */ public static @NonNull PluginManager createDefault(@NonNull Jenkins jenkins) { String pmClassName = SystemProperties.getString(CUSTOM_PLUGIN_MANAGER); - if (!StringUtils.isBlank(pmClassName)) { + if (pmClassName != null && !pmClassName.isBlank()) { LOGGER.log(FINE, String.format("Use of custom plugin manager [%s] requested.", pmClassName)); try { final Class klass = Class.forName(pmClassName).asSubclass(PluginManager.class); @@ -370,7 +370,7 @@ protected PluginManager(ServletContext context, File rootDir) { throw new UncheckedIOException(e); } String workDir = SystemProperties.getString(PluginManager.class.getName() + ".workDir"); - this.workDir = StringUtils.isBlank(workDir) ? null : new File(workDir); + this.workDir = workDir == null || workDir.isBlank() ? null : new File(workDir); strategy = createPluginStrategy(); } @@ -1429,7 +1429,7 @@ public HttpResponse doPluginsSearch(@QueryParameter String query, @QueryParamete for (UpdateSite site : Jenkins.get().getUpdateCenter().getSiteList()) { List sitePlugins = site.getAvailables().stream() .filter(plugin -> { - if (StringUtils.isBlank(query)) { + if (query == null || query.isBlank()) { return true; } return StringUtils.containsIgnoreCase(plugin.name, query) || @@ -1864,9 +1864,10 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl File tmpDir = Files.createTempDirectory("uploadDir").toFile(); ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, tmpDir)); List items = upload.parseRequest(req); - if (StringUtils.isNotBlank(items.get(1).getString())) { + String string = items.get(1).getString(); + if (string != null && !string.isBlank()) { // this is a URL deployment - fileName = items.get(1).getString(); + fileName = string; copier = new UrlPluginCopier(fileName); } else { // this is a file upload @@ -1909,7 +1910,7 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl } String deps = m.getMainAttributes().getValue("Plugin-Dependencies"); - if (StringUtils.isNotBlank(deps)) { + if (deps != null && !deps.isBlank()) { // now we get to parse it! String[] plugins = deps.split(","); for (String p : plugins) { @@ -1940,7 +1941,7 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl @Restricted(NoExternalUse.class) @RequirePOST public FormValidation doCheckPluginUrl(StaplerRequest request, @QueryParameter String value) throws IOException { - if (StringUtils.isNotBlank(value)) { + if (value != null && !value.isBlank()) { try { URL url = new URL(value); if (!url.getProtocol().startsWith("http")) { diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index 1759397d0b6d..15b5331427b1 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -115,7 +115,6 @@ import jenkins.util.SystemProperties; import jenkins.widgets.HasWidgets; import net.jcip.annotations.GuardedBy; -import org.apache.commons.lang.StringUtils; import org.jenkins.ui.icon.Icon; import org.jenkins.ui.icon.IconSet; import org.kohsuke.accmod.Restricted; @@ -1522,7 +1521,7 @@ public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOExc } String nExecutors = req.getSubmittedForm().getString("numExecutors"); - if (StringUtils.isBlank(nExecutors) || Integer.parseInt(nExecutors) <= 0) { + if (nExecutors == null || nExecutors.isBlank() || Integer.parseInt(nExecutors) <= 0) { throw new FormException(Messages.Slave_InvalidConfig_Executors(nodeName), "numExecutors"); } diff --git a/core/src/main/java/hudson/model/DirectoryBrowserSupport.java b/core/src/main/java/hudson/model/DirectoryBrowserSupport.java index cc83eefd0652..8083efa72dbf 100644 --- a/core/src/main/java/hudson/model/DirectoryBrowserSupport.java +++ b/core/src/main/java/hudson/model/DirectoryBrowserSupport.java @@ -63,7 +63,6 @@ import jenkins.util.SystemProperties; import jenkins.util.VirtualFile; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; import org.apache.tools.zip.ZipEntry; import org.apache.tools.zip.ZipOutputStream; import org.kohsuke.accmod.Restricted; @@ -280,7 +279,7 @@ private void serveFile(StaplerRequest req, StaplerResponse rsp, VirtualFile root if (zip) { rsp.setContentType("application/zip"); String includes, prefix; - if (StringUtils.isBlank(rest)) { + if (rest == null || rest.isBlank()) { includes = "**"; // JENKINS-19947, JENKINS-61473: traditional behavior is to prepend the directory name prefix = baseFile.getName(); diff --git a/core/src/main/java/hudson/model/TopLevelItemDescriptor.java b/core/src/main/java/hudson/model/TopLevelItemDescriptor.java index bfaf64c16f9e..16aa01807ff8 100644 --- a/core/src/main/java/hudson/model/TopLevelItemDescriptor.java +++ b/core/src/main/java/hudson/model/TopLevelItemDescriptor.java @@ -34,7 +34,6 @@ import jenkins.model.item_category.ItemCategory; import org.apache.commons.jelly.Script; import org.apache.commons.jelly.XMLOutput; -import org.apache.commons.lang.StringUtils; import org.jenkins.ui.icon.Icon; import org.jenkins.ui.icon.IconSet; import org.jenkins.ui.icon.IconSpec; @@ -215,8 +214,9 @@ public String getIconFilePathPattern() { @CheckForNull @Deprecated public String getIconFilePath(String size) { - if (!StringUtils.isBlank(getIconFilePathPattern())) { - return getIconFilePathPattern().replace(":size", size); + String iconFilePathPattern = getIconFilePathPattern(); + if (iconFilePathPattern != null && !iconFilePathPattern.isBlank()) { + return iconFilePathPattern.replace(":size", size); } return null; } diff --git a/core/src/main/java/hudson/model/User.java b/core/src/main/java/hudson/model/User.java index 6d8b83a793e3..a242385cb11a 100644 --- a/core/src/main/java/hudson/model/User.java +++ b/core/src/main/java/hudson/model/User.java @@ -78,7 +78,6 @@ import jenkins.security.UserDetailsCache; import jenkins.util.SystemProperties; import net.sf.json.JSONObject; -import org.apache.commons.lang.StringUtils; import org.jenkinsci.Symbol; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; @@ -795,7 +794,7 @@ static File getRootDir() { * @since 1.600 */ public static boolean isIdOrFullnameAllowed(@CheckForNull String id) { - if (StringUtils.isBlank(id)) { + if (id == null || id.isBlank()) { return false; } final String trimmedId = id.trim(); diff --git a/core/src/main/java/hudson/model/View.java b/core/src/main/java/hudson/model/View.java index 6bd923cd0268..fb0d2b0b8c88 100644 --- a/core/src/main/java/hudson/model/View.java +++ b/core/src/main/java/hudson/model/View.java @@ -106,7 +106,6 @@ import net.sf.json.JSON; import net.sf.json.JSONArray; import net.sf.json.JSONObject; -import org.apache.commons.lang.StringUtils; import org.jenkins.ui.icon.Icon; import org.jenkins.ui.icon.IconSet; import org.kohsuke.accmod.Restricted; @@ -1121,7 +1120,7 @@ public Categories doItemCategories(StaplerRequest req, StaplerResponse rsp, @Que int order = 0; String resUrl; - if (StringUtils.isNotBlank(iconStyle)) { + if (iconStyle != null && !iconStyle.isBlank()) { resUrl = req.getContextPath() + Jenkins.RESOURCE_PATH; } else { resUrl = null; @@ -1137,7 +1136,7 @@ public Categories doItemCategories(StaplerRequest req, StaplerResponse rsp, @Que metadata.put("description", descriptor.getDescription()); metadata.put("iconFilePathPattern", descriptor.getIconFilePathPattern()); String iconClassName = descriptor.getIconClassName(); - if (StringUtils.isNotBlank(iconClassName)) { + if (iconClassName != null && !iconClassName.isBlank()) { metadata.put("iconClassName", iconClassName); if (resUrl != null) { Icon icon = IconSet.icons diff --git a/core/src/main/java/hudson/model/ViewDescriptor.java b/core/src/main/java/hudson/model/ViewDescriptor.java index b4c016e4f1e4..f38e5d846d9a 100644 --- a/core/src/main/java/hudson/model/ViewDescriptor.java +++ b/core/src/main/java/hudson/model/ViewDescriptor.java @@ -35,7 +35,6 @@ import java.util.Objects; import jenkins.model.DirectlyModifiableTopLevelItemGroup; import jenkins.model.Jenkins; -import org.apache.commons.lang.StringUtils; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.DoNotUse; import org.kohsuke.stapler.AncestorInPath; @@ -141,7 +140,7 @@ public List> getJobFiltersDescriptors() { */ @SuppressWarnings("unused") // expose utility check method to subclasses protected FormValidation checkDisplayName(@NonNull View view, @CheckForNull String value) { - if (StringUtils.isBlank(value)) { + if (value == null || value.isBlank()) { // no custom name, no need to check return FormValidation.ok(); } diff --git a/core/src/main/java/hudson/security/SecurityRealm.java b/core/src/main/java/hudson/security/SecurityRealm.java index a134755fe95e..10437d614bce 100644 --- a/core/src/main/java/hudson/security/SecurityRealm.java +++ b/core/src/main/java/hudson/security/SecurityRealm.java @@ -679,7 +679,7 @@ public static String getFrom() { // Return encoded value or at least "/" in the case exception occurred during encode() // or if the encoded content is blank value - return StringUtils.isBlank(returnValue) ? "/" : returnValue; + return returnValue == null || returnValue.isBlank() ? "/" : returnValue; } private static class None extends SecurityRealm { diff --git a/core/src/main/java/hudson/tasks/BuildTrigger.java b/core/src/main/java/hudson/tasks/BuildTrigger.java index f6f17dab490c..ce19e30b56e4 100644 --- a/core/src/main/java/hudson/tasks/BuildTrigger.java +++ b/core/src/main/java/hudson/tasks/BuildTrigger.java @@ -418,7 +418,7 @@ public FormValidation doCheck(@AncestorInPath AbstractProject project, @QueryPar boolean hasProjects = false; while (tokens.hasMoreTokens()) { String projectName = tokens.nextToken().trim(); - if (StringUtils.isNotBlank(projectName)) { + if (projectName != null && !projectName.isBlank()) { Item item = Jenkins.get().getItem(projectName, project, Item.class); if (item == null) { Job nearest = Items.findNearest(Job.class, projectName, project.getParent()); diff --git a/core/src/main/java/hudson/tasks/Maven.java b/core/src/main/java/hudson/tasks/Maven.java index 4230da15d6f2..3c22790d383c 100644 --- a/core/src/main/java/hudson/tasks/Maven.java +++ b/core/src/main/java/hudson/tasks/Maven.java @@ -76,7 +76,6 @@ import jenkins.mvn.SettingsProvider; import jenkins.security.MasterToSlaveCallable; import net.sf.json.JSONObject; -import org.apache.commons.lang.StringUtils; import org.jenkinsci.Symbol; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; @@ -331,13 +330,13 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListen if (!S_PATTERN.matcher(targets).find()) { // check the given target/goals do not contain settings parameter already String settingsPath = SettingsProvider.getSettingsRemotePath(getSettings(), build, listener); - if (StringUtils.isNotBlank(settingsPath)) { + if (settingsPath != null && !settingsPath.isBlank()) { args.add("-s", settingsPath); } } if (!GS_PATTERN.matcher(targets).find()) { String settingsPath = GlobalSettingsProvider.getSettingsRemotePath(getGlobalSettings(), build, listener); - if (StringUtils.isNotBlank(settingsPath)) { + if (settingsPath != null && !settingsPath.isBlank()) { args.add("-gs", settingsPath); } } diff --git a/core/src/main/java/hudson/triggers/SCMTrigger.java b/core/src/main/java/hudson/triggers/SCMTrigger.java index 440f75cfa69b..e35a3b66af69 100644 --- a/core/src/main/java/hudson/triggers/SCMTrigger.java +++ b/core/src/main/java/hudson/triggers/SCMTrigger.java @@ -81,7 +81,6 @@ import jenkins.util.SystemProperties; import net.sf.json.JSONObject; import org.apache.commons.jelly.XMLOutput; -import org.apache.commons.lang.StringUtils; import org.jenkinsci.Symbol; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.DoNotUse; @@ -381,7 +380,7 @@ public FormValidation doCheckPollingThreadCount(@QueryParameter String value) { public FormValidation doCheckScmpoll_spec(@QueryParameter String value, @QueryParameter boolean ignorePostCommitHooks, @AncestorInPath Item item) { - if (StringUtils.isBlank(value)) { + if (value == null || value.isBlank()) { if (ignorePostCommitHooks) { return FormValidation.ok(Messages.SCMTrigger_no_schedules_no_hooks()); } else { diff --git a/core/src/main/java/hudson/util/io/ZipArchiver.java b/core/src/main/java/hudson/util/io/ZipArchiver.java index a189457a2861..66a4f21a3dc1 100644 --- a/core/src/main/java/hudson/util/io/ZipArchiver.java +++ b/core/src/main/java/hudson/util/io/ZipArchiver.java @@ -36,7 +36,6 @@ import java.nio.file.InvalidPathException; import java.nio.file.OpenOption; import java.nio.file.attribute.BasicFileAttributes; -import org.apache.commons.lang.StringUtils; import org.apache.tools.zip.Zip64Mode; import org.apache.tools.zip.ZipEntry; import org.apache.tools.zip.ZipOutputStream; @@ -62,7 +61,7 @@ final class ZipArchiver extends Archiver { @Restricted(NoExternalUse.class) ZipArchiver(OutputStream out, String prefix, OpenOption... openOptions) { this.openOptions = openOptions; - if (StringUtils.isBlank(prefix)) { + if (prefix == null || prefix.isBlank()) { this.prefix = ""; } else { this.prefix = Util.ensureEndsWith(prefix, "/"); diff --git a/core/src/main/java/jenkins/install/InstallState.java b/core/src/main/java/jenkins/install/InstallState.java index 3e1c2da9cbd5..4330d371337e 100644 --- a/core/src/main/java/jenkins/install/InstallState.java +++ b/core/src/main/java/jenkins/install/InstallState.java @@ -37,7 +37,6 @@ import jenkins.security.apitoken.ApiTokenPropertyConfiguration; import jenkins.security.stapler.StaplerAccessibleType; import jenkins.util.Timer; -import org.apache.commons.lang.StringUtils; /** * Jenkins install state. @@ -152,7 +151,8 @@ private static final class ConfigureInstance extends InstallState { public void initializeState() { // Skip this state if a boot script already configured the root URL // in case we add more fields in this page, this should be adapted - if (StringUtils.isNotBlank(JenkinsLocationConfiguration.getOrDie().getUrl())) { + String url = JenkinsLocationConfiguration.getOrDie().getUrl(); + if (url != null && !url.isBlank()) { InstallUtil.proceedToNextStateFrom(this); } } @@ -315,7 +315,7 @@ public void initializeState() { @Deprecated protected Object readResolve() { // If we get invalid state from the configuration, fallback to unknown - if (StringUtils.isBlank(name)) { + if (name == null || name.isBlank()) { LOGGER.log(Level.WARNING, "Read install state with blank name: ''{0}''. It will be ignored", name); return UNKNOWN; } diff --git a/core/src/main/java/jenkins/install/InstallUtil.java b/core/src/main/java/jenkins/install/InstallUtil.java index 9280b6c064c4..3d1bf24e267d 100644 --- a/core/src/main/java/jenkins/install/InstallUtil.java +++ b/core/src/main/java/jenkins/install/InstallUtil.java @@ -55,7 +55,6 @@ import jenkins.model.Jenkins; import jenkins.util.SystemProperties; import jenkins.util.xml.XMLUtils; -import org.apache.commons.lang.StringUtils; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; @@ -214,7 +213,7 @@ public static void saveLastExecVersion() { String version = Files.readString(Util.fileToPath(lastExecVersionFile), Charset.defaultCharset()); // JENKINS-37438 blank will force the setup // wizard regardless of current state of the system - if (StringUtils.isBlank(version)) { + if (version == null || version.isBlank()) { return FORCE_NEW_INSTALL_VERSION.toString(); } return version; diff --git a/core/src/main/java/jenkins/model/AssetManager.java b/core/src/main/java/jenkins/model/AssetManager.java index a3c9a657316a..5da61d203026 100644 --- a/core/src/main/java/jenkins/model/AssetManager.java +++ b/core/src/main/java/jenkins/model/AssetManager.java @@ -11,7 +11,6 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletResponse; import jenkins.ClassLoaderReflectionToolkit; -import org.apache.commons.lang.StringUtils; import org.jenkinsci.Symbol; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; @@ -76,7 +75,7 @@ public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOExceptio * doesn't find it, fall back to the parent classloader. */ private @CheckForNull URL findResource(@NonNull String path) throws IOException { - if (StringUtils.isBlank(path)) { + if (path == null || path.isBlank()) { return null; } diff --git a/core/src/main/java/jenkins/model/ProjectNamingStrategy.java b/core/src/main/java/jenkins/model/ProjectNamingStrategy.java index bdd9bfb377b8..76e9ff64587f 100644 --- a/core/src/main/java/jenkins/model/ProjectNamingStrategy.java +++ b/core/src/main/java/jenkins/model/ProjectNamingStrategy.java @@ -38,7 +38,6 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import javax.servlet.ServletException; -import org.apache.commons.lang.StringUtils; import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; @@ -172,7 +171,7 @@ public PatternProjectNamingStrategy(String namePattern, String description, bool @Override public void checkName(String name) { - if (StringUtils.isNotBlank(namePattern) && StringUtils.isNotBlank(name)) { + if ((namePattern != null && !namePattern.isBlank()) && (name != null && !name.isBlank())) { if (!Pattern.matches(namePattern, name)) { throw new Failure(description == null || description.isEmpty() ? Messages.Hudson_JobNameConventionNotApplyed(name, namePattern) : diff --git a/core/src/main/java/jenkins/security/ApiTokenProperty.java b/core/src/main/java/jenkins/security/ApiTokenProperty.java index 3e200b25fa2f..69904a0e4785 100644 --- a/core/src/main/java/jenkins/security/ApiTokenProperty.java +++ b/core/src/main/java/jenkins/security/ApiTokenProperty.java @@ -57,7 +57,6 @@ import net.jcip.annotations.Immutable; import net.sf.json.JSONArray; import net.sf.json.JSONObject; -import org.apache.commons.lang.StringUtils; import org.jenkinsci.Symbol; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.Beta; @@ -191,7 +190,7 @@ public boolean hasLegacyToken() { } public boolean matchesPassword(String token) { - if (StringUtils.isBlank(token)) { + if (token == null || token.isBlank()) { return false; } @@ -512,7 +511,7 @@ public HttpResponse doGenerateNewToken(@AncestorInPath User u, @QueryParameter S } final String tokenName; - if (StringUtils.isBlank(newTokenName)) { + if (newTokenName == null || newTokenName.isBlank()) { tokenName = Messages.Token_Created_on(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now())); } else { tokenName = newTokenName; @@ -548,7 +547,7 @@ public HttpResponse doAddFixedToken(@AncestorInPath User u, } final String tokenName; - if (StringUtils.isBlank(newTokenName)) { + if (newTokenName == null || newTokenName.isBlank()) { tokenName = String.format("Token created on %s", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now())); } else { tokenName = newTokenName; @@ -575,10 +574,10 @@ public HttpResponse doRename(@AncestorInPath User u, // only current user + administrator can rename token u.checkPermission(Jenkins.ADMINISTER); - if (StringUtils.isBlank(newName)) { + if (newName == null || newName.isBlank()) { return HttpResponses.errorJSON("The name cannot be empty"); } - if (StringUtils.isBlank(tokenUuid)) { + if (tokenUuid == null || tokenUuid.isBlank()) { // using the web UI this should not occur return HttpResponses.errorWithoutStack(400, "The tokenUuid cannot be empty"); } @@ -606,7 +605,7 @@ public HttpResponse doRevoke(@AncestorInPath User u, // only current user + administrator can revoke token u.checkPermission(Jenkins.ADMINISTER); - if (StringUtils.isBlank(tokenUuid)) { + if (tokenUuid == null || tokenUuid.isBlank()) { // using the web UI this should not occur return HttpResponses.errorWithoutStack(400, "The tokenUuid cannot be empty"); } @@ -644,7 +643,7 @@ public HttpResponse doRevokeAllExcept(@AncestorInPath User u, // only current user + administrator can revoke token u.checkPermission(Jenkins.ADMINISTER); - if (StringUtils.isBlank(tokenUuid)) { + if (tokenUuid == null || tokenUuid.isBlank()) { // using the web UI this should not occur return HttpResponses.errorWithoutStack(400, "The tokenUuid cannot be empty"); } diff --git a/core/src/main/java/jenkins/security/apitoken/ApiTokenStore.java b/core/src/main/java/jenkins/security/apitoken/ApiTokenStore.java index 67f9720216b8..917be3b0fa19 100644 --- a/core/src/main/java/jenkins/security/apitoken/ApiTokenStore.java +++ b/core/src/main/java/jenkins/security/apitoken/ApiTokenStore.java @@ -51,7 +51,6 @@ import jenkins.security.Messages; import net.jcip.annotations.Immutable; import net.sf.json.JSONObject; -import org.apache.commons.lang.StringUtils; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; @@ -110,7 +109,7 @@ public synchronized void reconfigure(@NonNull Map tokenStore } String name = receivedTokenData.getString("tokenName"); - if (StringUtils.isBlank(name)) { + if (name == null || name.isBlank()) { LOGGER.log(Level.INFO, "Empty name received for {0}, we do not care about it", hashedToken.uuid); return; } diff --git a/core/src/main/java/jenkins/tasks/filters/impl/RetainVariablesLocalRule.java b/core/src/main/java/jenkins/tasks/filters/impl/RetainVariablesLocalRule.java index cdce1001d89a..dbfe5ea86203 100644 --- a/core/src/main/java/jenkins/tasks/filters/impl/RetainVariablesLocalRule.java +++ b/core/src/main/java/jenkins/tasks/filters/impl/RetainVariablesLocalRule.java @@ -41,7 +41,6 @@ import jenkins.tasks.filters.EnvVarsFilterLocalRuleDescriptor; import jenkins.tasks.filters.EnvVarsFilterRuleContext; import jenkins.tasks.filters.EnvVarsFilterableBuilder; -import org.apache.commons.lang.StringUtils; import org.jenkinsci.Symbol; import org.jvnet.localizer.Localizable; import org.kohsuke.accmod.Restricted; @@ -87,7 +86,7 @@ private static List convertStringToList(@NonNull String variablesCommaSe String[] variablesArray = variablesCommaSeparated.split("\\s+"); List variables = new ArrayList<>(); for (String nameFragment : variablesArray) { - if (StringUtils.isNotBlank(nameFragment)) { + if (nameFragment != null && !nameFragment.isBlank()) { variables.add(nameFragment.toLowerCase(Locale.ENGLISH)); } } diff --git a/core/src/main/java/jenkins/triggers/ReverseBuildTrigger.java b/core/src/main/java/jenkins/triggers/ReverseBuildTrigger.java index 87ace6af6e94..38b578e0ce94 100644 --- a/core/src/main/java/jenkins/triggers/ReverseBuildTrigger.java +++ b/core/src/main/java/jenkins/triggers/ReverseBuildTrigger.java @@ -66,7 +66,6 @@ import jenkins.model.DependencyDeclarer; import jenkins.model.Jenkins; import jenkins.model.ParameterizedJobMixIn; -import org.apache.commons.lang.StringUtils; import org.jenkinsci.Symbol; import org.kohsuke.stapler.AncestorInPath; import org.kohsuke.stapler.DataBoundConstructor; @@ -214,7 +213,7 @@ public FormValidation doCheckUpstreamProjects(@AncestorInPath Job project, @Quer boolean hasProjects = false; while (tokens.hasMoreTokens()) { String projectName = tokens.nextToken().trim(); - if (StringUtils.isNotBlank(projectName)) { + if (projectName != null && !projectName.isBlank()) { Job item = Jenkins.get().getItem(projectName, project, Job.class); if (item == null) { Job nearest = Items.findNearest(Job.class, projectName, project.getParent()); diff --git a/core/src/main/java/jenkins/util/SystemProperties.java b/core/src/main/java/jenkins/util/SystemProperties.java index 200c95a4a3ff..d32a91e2db79 100644 --- a/core/src/main/java/jenkins/util/SystemProperties.java +++ b/core/src/main/java/jenkins/util/SystemProperties.java @@ -47,7 +47,6 @@ import javax.servlet.ServletContextListener; import jenkins.security.MasterToSlaveCallable; import jenkins.util.io.OnMaster; -import org.apache.commons.lang.StringUtils; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; @@ -102,7 +101,7 @@ public static final class Listener implements ServletContextListener, OnMaster { public void contextInitialized(ServletContextEvent event) { ServletContext theContext = event.getServletContext(); handler = key -> { - if (StringUtils.isNotBlank(key)) { + if (key != null && !key.isBlank()) { try { return theContext.getInitParameter(key); } catch (SecurityException ex) { diff --git a/core/src/main/java/jenkins/util/TreeString.java b/core/src/main/java/jenkins/util/TreeString.java index 455e48ff5847..3bcdc95d90ca 100644 --- a/core/src/main/java/jenkins/util/TreeString.java +++ b/core/src/main/java/jenkins/util/TreeString.java @@ -32,7 +32,6 @@ import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import java.io.Serializable; import java.util.Map; -import org.apache.commons.lang.StringUtils; /** * {@link TreeString} is an alternative string representation that saves the @@ -165,7 +164,8 @@ public String toString() { } public boolean isBlank() { - return StringUtils.isBlank(toString()); + String string = toString(); + return string == null || string.isBlank(); } public static String toString(final TreeString t) { diff --git a/core/src/main/java/jenkins/util/VirtualFile.java b/core/src/main/java/jenkins/util/VirtualFile.java index 609b18ec1c7e..bf9fc49bd48d 100644 --- a/core/src/main/java/jenkins/util/VirtualFile.java +++ b/core/src/main/java/jenkins/util/VirtualFile.java @@ -62,7 +62,6 @@ import jenkins.MasterToSlaveFileCallable; import jenkins.model.ArtifactManager; import jenkins.security.MasterToSlaveCallable; -import org.apache.commons.lang.StringUtils; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.types.AbstractFileSet; import org.apache.tools.ant.types.selectors.SelectorUtils; @@ -368,7 +367,7 @@ private List patterns(String patts) { public int zip(OutputStream outputStream, String includes, String excludes, boolean useDefaultExcludes, String prefix, OpenOption... openOptions) throws IOException { String correctPrefix; - if (StringUtils.isBlank(prefix)) { + if (prefix == null || prefix.isBlank()) { correctPrefix = ""; } else { correctPrefix = Util.ensureEndsWith(prefix, "/"); diff --git a/core/src/main/java/org/jenkins/ui/symbol/Symbol.java b/core/src/main/java/org/jenkins/ui/symbol/Symbol.java index 2dca039d8e92..19ae8497fa35 100644 --- a/core/src/main/java/org/jenkins/ui/symbol/Symbol.java +++ b/core/src/main/java/org/jenkins/ui/symbol/Symbol.java @@ -55,19 +55,19 @@ public static String get(@NonNull SymbolRequest request) { String symbol = SYMBOLS .computeIfAbsent(identifier, key -> new ConcurrentHashMap<>()) .computeIfAbsent(name, key -> loadSymbol(identifier, key)); - if (StringUtils.isNotBlank(tooltip) && StringUtils.isBlank(htmlTooltip)) { + if ((tooltip != null && !tooltip.isBlank()) && (htmlTooltip == null || htmlTooltip.isBlank())) { symbol = symbol.replaceAll("" + Util.xmlEscape(title) + "" + symbol; } return symbol; diff --git a/test/src/test/java/jenkins/diagnostics/RootUrlNotSetMonitorTest.java b/test/src/test/java/jenkins/diagnostics/RootUrlNotSetMonitorTest.java index decee0412bea..bd98175ab936 100644 --- a/test/src/test/java/jenkins/diagnostics/RootUrlNotSetMonitorTest.java +++ b/test/src/test/java/jenkins/diagnostics/RootUrlNotSetMonitorTest.java @@ -25,11 +25,11 @@ package jenkins.diagnostics; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import hudson.model.AdministrativeMonitor; import jenkins.model.JenkinsLocationConfiguration; -import org.apache.commons.lang.StringUtils; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.Issue; @@ -45,7 +45,9 @@ public class RootUrlNotSetMonitorTest { public void testWithRootUrl_configured() { // test relies on the default JTH behavior JenkinsLocationConfiguration config = JenkinsLocationConfiguration.get(); - assertTrue(StringUtils.isNotBlank(config.getUrl())); + String url = config.getUrl(); + assertNotNull(url); + assertFalse(url.isBlank()); RootUrlNotSetMonitor monitor = j.jenkins.getExtensionList(AdministrativeMonitor.class).get(RootUrlNotSetMonitor.class); assertFalse("Monitor must not be activated", monitor.isActivated());