Update deprecated default string function (#7239)

#### What type of PR is this?
/kind cleanup

#### What this PR does / why we need it:
Replaces deprecated functions (`String defaultString(final String str, final String nullDefault)`) with its recommended alternatives

See 29ccc7665f/src/main/java/org/apache/commons/lang3/StringUtils.java (L1635) for more.

#### Does this PR introduce a user-facing change?

```release-note
None
```
pull/7257/head
edops973 2025-02-26 17:12:54 +07:00 committed by GitHub
parent 0cdd8d1469
commit 8305822c09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 21 additions and 20 deletions

View File

@ -5,6 +5,7 @@ import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import java.util.Objects;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@ -83,7 +84,7 @@ public class Theme extends AbstractExtension {
@NonNull
public String getVersion() {
return StringUtils.defaultString(this.version, WILDCARD);
return Objects.toString(this.version, WILDCARD);
}
/**
@ -96,14 +97,14 @@ public class Theme extends AbstractExtension {
if (StringUtils.isNotBlank(this.requires)) {
return this.requires;
}
return StringUtils.defaultString(this.require, WILDCARD);
return Objects.toString(this.require, WILDCARD);
}
/**
* Compatible with {@link #website} property.
*/
public String getHomepage() {
return StringUtils.defaultString(this.homepage, this.website);
return Objects.toString(this.homepage, this.website);
}
}

View File

@ -6,6 +6,7 @@ import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.web.reactive.function.server.ServerRequest;
import run.halo.app.extension.ListResult;
import run.halo.app.infra.utils.PathUtils;
import java.util.Objects;
/**
* A utility class for template page url.
@ -83,7 +84,7 @@ public class PageUrlUtils {
return PathUtils.combinePath(segments);
}
}
return StringUtils.defaultString(path, "/");
return Objects.toString(path, "/");
}
private static String appendPagePart(String path, long page) {

View File

@ -117,6 +117,5 @@ public class SinglePageQuery extends SortableRequest {
.description("SinglePages filtered by keyword.")
.implementation(String.class)
.required(false));
;
}
}

View File

@ -31,7 +31,7 @@ public record CommentEmailOwner(String email, String avatar, String displayName,
Comment.CommentOwner commentOwner = new Comment.CommentOwner();
commentOwner.setKind(Comment.CommentOwner.KIND_EMAIL);
// email nullable
commentOwner.setName(StringUtils.defaultString(email, StringUtils.EMPTY));
commentOwner.setName(StringUtils.defaultString(email));
commentOwner.setDisplayName(displayName);
Map<String, String> annotations = new LinkedHashMap<>();

View File

@ -2,8 +2,8 @@ package run.halo.app.core.reconciler;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import run.halo.app.core.extension.ReverseProxy;
import run.halo.app.extension.ExtensionClient;
@ -99,7 +99,7 @@ public class ReverseProxyReconciler implements Reconciler<Reconciler.Request> {
if (labels == null) {
return PluginConst.SYSTEM_PLUGIN_NAME;
}
return StringUtils.defaultString(labels.get(PluginConst.PLUGIN_NAME_LABEL_NAME),
return Objects.toString(labels.get(PluginConst.PLUGIN_NAME_LABEL_NAME),
PluginConst.SYSTEM_PLUGIN_NAME);
}
}

View File

@ -45,17 +45,17 @@ public class RequestInfo {
String apiVersion, String resource, String name, String subresource, String subName,
String[] parts) {
this.isResourceRequest = isResourceRequest;
this.path = StringUtils.defaultString(path, "");
this.namespace = StringUtils.defaultString(namespace, "");
this.userspace = StringUtils.defaultString(userspace, "");
this.verb = StringUtils.defaultString(verb, "");
this.apiPrefix = StringUtils.defaultString(apiPrefix, "");
this.apiGroup = StringUtils.defaultString(apiGroup, "");
this.apiVersion = StringUtils.defaultString(apiVersion, "");
this.resource = StringUtils.defaultString(resource, "");
this.subresource = StringUtils.defaultString(subresource, "");
this.subName = StringUtils.defaultString(subName, "");
this.name = StringUtils.defaultString(name, "");
this.path = StringUtils.defaultString(path);
this.namespace = StringUtils.defaultString(namespace);
this.userspace = StringUtils.defaultString(userspace);
this.verb = StringUtils.defaultString(verb);
this.apiPrefix = StringUtils.defaultString(apiPrefix);
this.apiGroup = StringUtils.defaultString(apiGroup);
this.apiVersion = StringUtils.defaultString(apiVersion);
this.resource = StringUtils.defaultString(resource);
this.subresource = StringUtils.defaultString(subresource);
this.subName = StringUtils.defaultString(subName);
this.name = StringUtils.defaultString(name);
this.parts = Objects.requireNonNullElseGet(parts, () -> new String[] {});
}
}

View File

@ -116,7 +116,7 @@ public class RequestInfoFactory {
return requestInfo;
}
requestInfo.apiGroup = StringUtils.defaultString(currentParts[0], "");
requestInfo.apiGroup = StringUtils.defaultString(currentParts[0]);
currentParts = Arrays.copyOfRange(currentParts, 1, currentParts.length);
}
requestInfo.isResourceRequest = true;