-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-52792][CORE] Remove commons-lang3 dependency from network-common
#51476
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
Conversation
| EventLoopGroup workerGroup = NettyUtils.createEventLoop(ioMode, conf.serverThreads(), | ||
| conf.getModuleName() + "-server"); | ||
|
|
||
| boolean isNotWindows = !System.getProperty("os.name").regionMatches(true, 0, "Windows", 0, 7); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the equivalent of the original.
public static final boolean IS_OS_WINDOWS = getOsMatchesName(OS_NAME_WINDOWS_PREFIX);return isOsNameMatch(OS_NAME, osNamePrefix);return Strings.CI.startsWith(osName, osNamePrefix);return CharSequenceUtils.regionMatches(str, ignoreCase, 0, prefix, 0, preLen);return ((String) cs).regionMatches(ignoreCase, thisStart, (String) substring, start, length);public static final String OS_NAME = SystemProperties.getOsName();return getProperty(OS_NAME);public static final String OS_NAME = "os.name";There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirmed that OS_NAME_WINDOWS_PREFIX is "Windows".
// SystemUtils.java
private static boolean getOsMatchesName(final String osNamePrefix) {
return isOsNameMatch(OS_NAME, osNamePrefix);
}
static boolean isOsNameMatch(final String osName, final String osNamePrefix) {
if (osName == null) {
return false;
}
return osName.startsWith(osNamePrefix);
}
public static final String OS_NAME = SystemProperties.getOsName();
// SystemProperties.java
public static String getOsName() {
return getProperty(OS_NAME);
}
public static final String OS_NAME = "os.name";
|
Could you review this PR, @viirya ? |
common/network-common/src/main/java/org/apache/spark/network/server/TransportServer.java
Outdated
Show resolved
Hide resolved
|
Thank you for reviewing. It's updated like the following. String name = System.getProperty("os.name");
boolean isNotWindows = 7 > name.length() || !name.regionMatches(true, 0, "Windows", 0, 7); |
viirya
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending CI
|
Thank you so much, @viirya ! |
|
Late LGTM. |
| conf.getModuleName() + "-server"); | ||
|
|
||
| String name = System.getProperty("os.name"); | ||
| boolean isNotWindows = 7 > name.length() || !name.regionMatches(true, 0, "Windows", 0, 7); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We dont need the 7 > name.length() || here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's originated from the previous commons-lang3 code. Initially, I also thought like you. However, after Liang-Chi commented, I realized that we need it in the following case, @mridulm .
If System.getProperty("os.name") == Win, 7 > name.length() will return true here. It means isNotWindows = true. Otherwise, isNotWindows becomes false for Win.
jshell> String name = "Win"
name ==> "Win"
jshell> !name.regionMatches(true, 0, "Windows", 0, 1)
$3 ==> false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scala> val name = "Win"
name: String = Win
scala> !name.regionMatches(true, 0, "Windows", 0, 7)
res2: Boolean = true
scala>
It should be 0, 7), no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, the length check comes from commons-lang3's startsWith.
I recommended to also add the check as I thought that regionMatches will throw StringIndexOutOfBoundsException if the length of str is less than preLen`, based on search answer from Google.
But seems in @mridulm's test above, it doesn't. The source code of regionMatches can confirm it.
public boolean regionMatches(int toffset, String other, int ooffset, int len) {
// Note: toffset, ooffset, or len might be near -1>>>1.
if ((ooffset < 0) || (toffset < 0) ||
(toffset > (long)length() - len) ||
(ooffset > (long)other.length() - len)) {
return false;
}
...
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a follow-up.
What changes were proposed in this pull request?
This PR aims to remove
commons-lang3dependency fromnetwork-commonmodule.Why are the changes needed?
To make
network-commonmodule independent from the 3rd-party dependency and its vulnerability.BEFORE
AFTER
Does this PR introduce any user-facing change?
No behavior change.
How was this patch tested?
Pass the CIs.
Was this patch authored or co-authored using generative AI tooling?
No.