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

[MNG-6825] Get rid of commons-lang #1080

Merged
merged 2 commits into from
Apr 6, 2023
Merged

[MNG-6825] Get rid of commons-lang #1080

merged 2 commits into from
Apr 6, 2023

Conversation

gnodet
Copy link
Contributor

@gnodet gnodet commented Apr 4, 2023

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

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

I like a lot of this very much. I do want to avoid introducing yet more utils classes though.

@@ -158,7 +158,7 @@ public void testCalculateDegreeOfConcurrency() {
int cpus = Runtime.getRuntime().availableProcessors();
assertEquals((int) (cpus * 2.2), cli.calculateDegreeOfConcurrency("2.2C"));
assertEquals(1, cli.calculateDegreeOfConcurrency("0.0001C"));
assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("2.C"));
assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("2.xC"));
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why this changed here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When changing the related code, I found out that 2.C was rejected early, although fully supported, so the test ended up failing after removing the early test which was using commons-lang Validate, as this part is completely duplicated by the exception thrown by the Float.parseFloat which also validates the syntax.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, so it's an extra test. That's fine, but I suggest also keeping

assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("2.C"));

Copy link
Contributor Author

@gnodet gnodet Apr 5, 2023

Choose a reason for hiding this comment

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

It's not really an extra test per se, I saw it as a test checking a bad float syntax. That's still the case.

I can't keep really the old test, because that test would not throw an exception anymore, as 2. is a legit float number according to the Float.parseFloat which is now used to validate the syntax. So while it is of course doable, it would actually add some specific code in the calculateDegreeOfConcurrentcy method simply to ensure this test fails. I'm not really struck by the fact that 2. is correctly parsed, and therefore that 2.C is a valid degree of concurrency, so I'd rather keep the code lean and accept this use case as valid.

Copy link
Contributor

Choose a reason for hiding this comment

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

So this is a behavior change and a bug fix? That's good, but probably needs a specific Jira issue focused on this particularly, and an individual PR. Otherwise if this behavior change causes problems it's going to be quite hard to backtrack to this change in the middle of all the other refactoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a behaviour change for sure, whether this is considered a bug can be discussed I suppose. I'll raise a JIRA for that one and rebase on top of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've splitted in two commits (not to be squashed) and two JIRA issues...

@timtebeek
Copy link
Contributor

Great to see these changes! I think the is(Not)Empty cases to move away from utils can also be reflected in an automated migration if you'd like me to roll that out across all of Maven. I think that was the most common use of utils.

Other cases that came up in discussion elsewhere are not as clear in the general case, but can be automated in specific cases. For instance the utils split methods take a separator as a literal, rather than the regex it can be for String.split. We can explore what we can replace with JDK calls already, now, and I'll hold off on further Commons Lang changes while we do so.

I'm traveling this week, so can't fully dive in, but hope to revisit the automations next week. Let me know if there's any over replacements that you'd like to distill from this one. Only looking to help & amplify changes such as this PR.

@gnodet
Copy link
Contributor Author

gnodet commented Apr 5, 2023

Great to see these changes! I think the is(Not)Empty cases to move away from utils can also be reflected in an automated migration if you'd like me to roll that out across all of Maven. I think that was the most common use of utils.

Other cases that came up in discussion elsewhere are not as clear in the general case, but can be automated in specific cases. For instance the utils split methods take a separator as a literal, rather than the regex it can be for String.split. We can explore what we can replace with JDK calls already, now, and I'll hold off on further Commons Lang changes while we do so.

I'm traveling this week, so can't fully dive in, but hope to revisit the automations next week. Let me know if there's any over replacements that you'd like to distill from this one. Only looking to help & amplify changes such as this PR.

Yes, the split calls can be translated directly when the separator is a one-char string. Other cases may need to be handled differently.

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

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

Looking good. The behavior change in MavenCli perhaps needs to be split out to a separate PR/issue though.

@@ -158,7 +158,7 @@ public void testCalculateDegreeOfConcurrency() {
int cpus = Runtime.getRuntime().availableProcessors();
assertEquals((int) (cpus * 2.2), cli.calculateDegreeOfConcurrency("2.2C"));
assertEquals(1, cli.calculateDegreeOfConcurrency("0.0001C"));
assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("2.C"));
assertThrows(IllegalArgumentException.class, () -> cli.calculateDegreeOfConcurrency("2.xC"));
Copy link
Contributor

Choose a reason for hiding this comment

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

So this is a behavior change and a bug fix? That's good, but probably needs a specific Jira issue focused on this particularly, and an individual PR. Otherwise if this behavior change causes problems it's going to be quite hard to backtrack to this change in the middle of all the other refactoring.

Also fix the thrown exception to report valid syntaxes without assuming the user intent (for example "0.5c" would say it's not an int...)
@gnodet gnodet force-pushed the MNG-6825 branch 2 times, most recently from b3ee1a0 to 43eac66 Compare April 5, 2023 13:58
@gnodet gnodet requested review from elharo and khmarbaise April 5, 2023 17:32
Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

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

Looking good. Just a few nits.

<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
<dependencies />
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need the empty element or can we just drop it?

@@ -90,7 +88,9 @@ private String loadMavenVersion() {

@Override
public boolean isMavenVersion(String versionRange) {
Validate.notBlank(versionRange, "versionRange can neither be null, empty nor blank");
if (!(versionRange != null && !versionRange.isEmpty())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

slightly clearer:

if (versionRange == null || versionRange.isEmpty())

@@ -90,7 +88,9 @@ private String loadMavenVersion() {

@Override
public boolean isMavenVersion(String versionRange) {
Validate.notBlank(versionRange, "versionRange can neither be null, empty nor blank");
if (!(versionRange != null && !versionRange.isEmpty())) {
throw new IllegalArgumentException("versionRange can neither be null nor empty");
Copy link
Contributor

Choose a reason for hiding this comment

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

better to use a NullPointerException for null. The tests below suggest this was the existing behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've always disliked throwing NPE explicitly and this will complicate the code as the test need to be split... Imho, in all cases, those are illegal arguments...
I'm going to commit the following:

        if (Objects.requireNonNull(versionRange, "versionRange cannot be null").isEmpty()) {
            throw new IllegalArgumentException("versionRange cannot be empty");
        }

Copy link
Contributor

Choose a reason for hiding this comment

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

That works :-)

@gnodet gnodet force-pushed the MNG-6825 branch 2 times, most recently from deecf96 to 10a2e87 Compare April 5, 2023 18:46
@gnodet gnodet requested a review from elharo April 5, 2023 18:51
@gnodet gnodet merged commit b2ee29e into apache:master Apr 6, 2023
@gnodet gnodet added this to the 4.0.0-alpha-6 milestone May 17, 2023
@gnodet gnodet deleted the MNG-6825 branch November 18, 2023 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants