Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further reduce usages of StringUtils #9044

Merged
merged 13 commits into from
Mar 27, 2024

Conversation

BobDu
Copy link
Member

@BobDu BobDu commented Mar 16, 2024

like #6270

Testing done

Proposed changelog entries

  • JENKINS-XXXXX, human-readable text

Proposed upgrade guidelines

N/A

Submitter checklist

Desired reviewers

@mention

Before the changes are marked as ready-for-merge:

Maintainer checklist

@MarkEWaite MarkEWaite added the skip-changelog Should not be shown in the changelog label Mar 16, 2024
@NotMyFault NotMyFault requested a review from a team March 18, 2024 14:58
Copy link
Contributor

@StefanSpieker StefanSpieker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I briefly reviewed this PR, I'm not sure if all replacements are equivalent. At least the StringUtils.defaultString should be replaced by the suggestion - not sure that all imports still fit

cli/src/main/java/hudson/cli/CLI.java Show resolved Hide resolved
core/src/main/java/hudson/model/Slave.java Outdated Show resolved Hide resolved
core/src/main/java/hudson/tasks/BuildTrigger.java Outdated Show resolved Hide resolved
BobDu added 12 commits March 22, 2024 19:23
Signed-off-by: Bob Du <i@bobdu.cc>
Signed-off-by: Bob Du <i@bobdu.cc>
Signed-off-by: Bob Du <i@bobdu.cc>
Signed-off-by: Bob Du <i@bobdu.cc>
Signed-off-by: Bob Du <i@bobdu.cc>
Signed-off-by: Bob Du <i@bobdu.cc>
Signed-off-by: Bob Du <i@bobdu.cc>
Signed-off-by: Bob Du <i@bobdu.cc>
Signed-off-by: Bob Du <i@bobdu.cc>
Signed-off-by: Bob Du <i@bobdu.cc>
Signed-off-by: Bob Du <i@bobdu.cc>
if (o.endsWith(removeSuffix2)) {
o = o.substring(0, o.length() - removeSuffix2.length());
}
final String expectedOrigin = o;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra o variable seems like an unnecessary layer of indirection for the reader. Why not just name it expectedOrigin to begin with and remove this line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expectedOrigin is a local variable used in lambda, it must be a final or effectively final.

Of course we can set o as another name for readability, but I think it is not very necessary as a temporary variable.

core/src/main/java/hudson/PluginManager.java Outdated Show resolved Hide resolved
Signed-off-by: Bob Du <i@bobdu.cc>
Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Many thanks for this contribution. Just two minor comments and I am ready to approve this PR.

Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the PR!

Copy link
Contributor

@MarkEWaite MarkEWaite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is now ready for merge. We will merge it after approximately 24 hours if there is no negative feedback.

/label ready-for-merge

@comment-ops-bot comment-ops-bot bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Mar 26, 2024
@MarkEWaite MarkEWaite merged commit 8197702 into jenkinsci:master Mar 27, 2024
17 checks passed
@@ -65,7 +64,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
HttpServletResponse rsp = (HttpServletResponse) response;
String authorization = req.getHeader("Authorization");

if (StringUtils.startsWithIgnoreCase(authorization, "Basic ")) {
if (authorization != null && authorization.toLowerCase().startsWith("Basic ".toLowerCase())) {
Copy link
Member

@jglick jglick Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it is unlikely to matter in practice, this is not a sound replacement. If a request was sent with

AUTHORIZATION: BASIC czNjcjN0

then a server running in Turkish locale (e.g., #9066, though here it is the server not client locale which matters) would fail this clause because

"basıc cznjcjn0".startsWith("basic ")

is false.

In general, you always want to pass the Locale argument (almost always Locale.ROOT) to toLowerCase / toUpperCase.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BobDu Is it worth filing a follow-up PR to address the above feedback? Or do we think the code is fine as-is?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree always add Locale.ROOT arg to toLowerCase method is a best practices.
Already make a new PR #9162

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback skip-changelog Should not be shown in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants