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

Replaced all [equals() -> "==", HashSet -> EnumSet, HashMap -> EnumMap] calls for enum types #5309

Merged
merged 1 commit into from
Feb 7, 2023

Conversation

tbw777
Copy link
Contributor

@tbw777 tbw777 commented Jan 18, 2023

These changes are more readable, faster and safer at compile and run-time. Also == is null-safe than equals.

@tbw777 tbw777 changed the title Replaced all [equals() -> "==", HashSet -> EnumSet, HashMap -> EnumMa… Replaced [equals() -> "==", HashSet -> EnumSet, HashMap -> EnumMap] calls for enum types Jan 18, 2023
@tbw777 tbw777 changed the title Replaced [equals() -> "==", HashSet -> EnumSet, HashMap -> EnumMap] calls for enum types Replaced all [equals() -> "==", HashSet -> EnumSet, HashMap -> EnumMap] calls for enum types Jan 18, 2023
Copy link
Member

@BradWalker BradWalker left a comment

Choose a reason for hiding this comment

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

You've changed the modular import of discrete classes into a "include the entire kitchen sink" method.

This is a problem. It breaks the jdeps(1) dependency mapping. In addition, it kills the modularity of the project.

For this reason, I have to give it a -1. Can you please fix changes like this and resubmit.

@BradWalker BradWalker added the do not merge Don't merge this PR, it is not ready or just demonstration purposes. label Jan 18, 2023
@tbw777 tbw777 requested a review from BradWalker January 18, 2023 10:32
@mbien mbien added the ci:all-tests [ci] enable all tests label Jan 19, 2023
@errael
Copy link
Contributor

errael commented Jan 19, 2023

equals() -> "=="

Wouldn't Objects.equals(thing1,thing2) be a better choice? It's forward compatible, consider if any object add an equals method. And it handles null object OK.

@tbw777
Copy link
Contributor Author

tbw777 commented Jan 19, 2023

I think == is more preffered becouse of no methods used and also because compile time type checking

I was scaned the project and no enums with equals exist. Actual regexp:
^[^\"')(;,\;,\\s*{}/](\s)enum\s+[^{}/\[\]%&?@!#$\^\*<>]+\s*((implements)\s*[^{}/\[\]%&?@!#$\^\*]+\s*,\s)*{(.|\n)*public\s+boolean\s+equals

Exclusions:

  1. enterprise/payara.tooling/src/org/netbeans/modules/payara/tooling/data/PayaraVersion.java
  @Override
  public boolean equals(PayaraPlatformVersionAPI version) {
      throw new UnsupportedOperationException("Not supported yet.");| Templates.
  }
  1. enterprise/glassfish.tooling/src/org/netbeans/modules/glassfish/tooling/data/GlassFishVersion.java
 public boolean equals(final GlassFishVersion version) {
     if (version == null) {
         return false;
     } else {
         return this.major == version.major
                 && this.minor == version.minor
                 && this.update == version.update
                 && this.build == version.build;
     }
 }

And as described in https://docs.oracle.com/javase/specs/jls/se19/html/jls-8.html#jls-8.9

8.9.1. Enum Constants
Because there is only one instance of each enum constant, it is permitted to use the == operator in place of the equals method when comparing two object references if it is known that at least one of them refers to an enum constant.

The equals method in Enum is a final method that merely invokes super.equals on its argument and returns the result, thus performing an identity comparison.

@errael
Copy link
Contributor

errael commented Jan 19, 2023

In my earlier/first quick glance, I thought I saw a non-enum change from .equals to ==. I must have been hallucinating, I don't see it now. Sorry for the noise.

@tbw777
Copy link
Contributor Author

tbw777 commented Jan 19, 2023

In my earlier/first quick glance, I thought I saw a non-enum change from .equals to ==. I must have been hallucinating, I don't see it now. Sorry for the noise.

Any feedback are welcome

@tbw777 tbw777 requested review from errael and BradWalker and removed request for BradWalker and errael January 20, 2023 02:38
@errael
Copy link
Contributor

errael commented Jan 20, 2023

tbw777 requested review from errael

@tbw777 I'm not a NetBeans committer, I looked through it, looks OK. I think you're better off getting someone part of the NetBeans Organization for review.

Copy link
Contributor

@errael errael left a comment

Choose a reason for hiding this comment

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

Looks OK.

I did not consider, from #5309 (review), the

You've changed the modular import of discrete classes into a

Which is probably most important.

@tbw777
Copy link
Contributor Author

tbw777 commented Jan 20, 2023

@errael
This comment was fixed after in new push. Click compare to review. Is problem actual or no? Ty

@BradWalker BradWalker removed the do not merge Don't merge this PR, it is not ready or just demonstration purposes. label Jan 22, 2023
@BradWalker
Copy link
Member

I removed my "do not merge" tag.. Thanks for fixing up the import statements.

@mbien mbien added this to the NB18 milestone Jan 27, 2023
@apache apache locked and limited conversation to collaborators Feb 4, 2023
@apache apache unlocked this conversation Feb 4, 2023
Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

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

looks good to me.

@mbien
Copy link
Member

mbien commented Feb 4, 2023

thanks for reviewing @BradWalker @errael, going to merge when all tests pass.

Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

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

on second thought. We can't merge this in current form. Luckily the tests caught a problem.

EnumSet.copyOf(Collection) does not allow empty collections. All changes which use that method have to be checked again and/or reverted.

@mbien mbien added the do not merge Don't merge this PR, it is not ready or just demonstration purposes. label Feb 4, 2023
@tbw777
Copy link
Contributor Author

tbw777 commented Feb 4, 2023

@mbien reverted

@tbw777 tbw777 removed the request for review from BradWalker February 4, 2023 08:39
@tbw777 tbw777 requested a review from errael February 4, 2023 21:13
@mbien
Copy link
Member

mbien commented Feb 4, 2023

please revert all changes to empty set and singleton sets. One is immutable the other is not.

you are now randomly changing already reviewed PRs.

@tbw777
Copy link
Contributor Author

tbw777 commented Feb 4, 2023

i will revert later

@errael
Copy link
Contributor

errael commented Feb 4, 2023

please revert all changes to empty set and singleton sets. One is immutable the other is not.

@mbien @tbw777 I don't know git/github that well (I use mercurial) Is there a way to remove/revert the last change, rather than add/force another change on top of that? If another change is added on top of the last one, it seems difficult to know that all the empty/singleton changes are removed.

If the last change is removed, then the relatively small cleanup change could be added.

Side question. There seems to be at least two method to evolving PRs.

  1. Multiple commits with squash when merged
  2. Use force and keep it a single commit

Is 1. easier to work with (considering the current situation). They should give the same result, right?

Does NetBeans have guidance about this?

@mbien
Copy link
Member

mbien commented Feb 4, 2023

Side question. There seems to be at least two method to evolving PRs.

1. Multiple commits with squash when merged

we don't let gh squash third party PRs since gh does sometimes weird things with author information which depends on how the account is set up. PRs like this one here are merged as is - so the final commits are important and they are also checked via the paperwork job.

2. Use force and keep it a single commit

there is no rule. Not all PRs will be a single commit after merge. Some are better to be merged as multiple commits. Esp if the author does a bugfix + refactoring. Those have to be kept separate.

whatever makes it easier, there is no rule as long individual commits are buildable and green - otherwise this will cause trouble on git bisect.

This PR here was basically ready and only needed the fix for copyOf. I don't understand what is going on now tbh but I have no time to review it anyway atm. This will need a full review again.

(force pushes can be reviewed via the delta on github, so it is usually no problem as long the delta is small)

@neilcsmith-net
Copy link
Member

neilcsmith-net commented Feb 5, 2023

Side question. There seems to be at least two method to evolving PRs.

  1. Multiple commits with squash when merged
  2. Use force and keep it a single commit

Is 1. easier to work with (considering the current situation). They should give the same result, right?

@errael side answer 😄 please don't squash and merge. Both GitHub UI and CLI have (different) negative side effects there. Do agree that multiple commits can be better when kept during reviews though. PR branches are generally writable by committers as well as authors, so squashing and force pushing into the PR branch (where warranted) for final checks before merging is ideal IMO.

@errael
Copy link
Contributor

errael commented Feb 5, 2023

(force pushes can be reviewed via the delta on github, so it is usually no problem as long the delta is small)

Yeah, "Compare" is one of my favorite buttons.

To be clear: as evidenced by the compare buttons the changes made by the last forced push are known (at least to github). Is there a way to back up to a particular spot?

2d81672
GoodBase

was pretty clean

It had a few more changes than expected, but they were in line with the goal of this PR and looked OK. Only dealt with HashSet --> EnumSet

There were a small handful of items that drew my attention including a few things that got lost from the previous change.

@tbw777
Copy link
Contributor Author

tbw777 commented Feb 5, 2023

FIXED

@tbw777 tbw777 requested review from mbien and BradWalker and removed request for errael, mbien and BradWalker February 5, 2023 06:32
@mbien
Copy link
Member

mbien commented Feb 5, 2023

looks like an import is missing.

   [repeat] /home/runner/work/netbeans/netbeans/enterprise/websvc.rest/src/org/netbeans/modules/websvc/rest/support/JavaSourceHelper.java:650: error: cannot find symbol
   [repeat]         modifierSet.addAll(Arrays.asList(modifiers));
   [repeat]                            ^

…p] calls for enum types

These changes are more readable, faster and safer at compile and run-time. Also == is null-safe than equals.
@tbw777
Copy link
Contributor Author

tbw777 commented Feb 5, 2023

Its because i havnt successful local builds since last days. I dont know what to do with a new message:

javafx-nbms:
[genkey] Generating Key for netbeans-bundled
[genkey] keytool error: java.security.KeyStoreException: Key protection algorithm not found: java.security.UnrecoverableKeyException: Encrypt Private Key failed: getSecretKey failed: Password is not ASCII
[genkey] Generating 2а048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 90 days
[genkey] for: CN=Ant Group, OU=NetBeans, O=Apache.org, C=US
[nbmerge] Failed to build target: all-updatecenters

Excuse me
I was reviewed code again and there is no other red imports found.

@matthiasblaesing
Copy link
Contributor

Its because i havnt successful local builds since last days. I dont know what to do with a new message:

javafx-nbms:
[genkey] Generating Key for netbeans-bundled
[genkey] keytool error: java.security.KeyStoreException: Key protection algorithm not found: java.security.UnrecoverableKeyException: Encrypt Private Key failed: getSecretKey failed: Password is not ASCII
[genkey] Generating 2а048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 90 days
[genkey] for: CN=Ant Group, OU=NetBeans, O=Apache.org, C=US
[nbmerge] Failed to build target: all-updatecenters

Excuse me

I answered on the mailing list and you answered, that you did not change anything. You did not mention if you even tried to ensure, that the path you are building in only contains ascii characters.

There is no general problem in master, I build multiple time today from it and it works as always.

Please don't push PRs without at least ensuring that the changes actually work and the minimal validation for that is, that it compiles.

@mbien
Copy link
Member

mbien commented Feb 5, 2023

ran a build locally of this PR and it builds now. Enabling the tests again.

@tbw777
Copy link
Contributor Author

tbw777 commented Feb 5, 2023

@matthiasblaesing

I agree
You are right

The problem was in non ascii path. Now i can check all builds locally.

@errael
Copy link
Contributor

errael commented Feb 5, 2023

Before #5309 (review) comment, I reviewed the PR and updates pretty carefully. After this comment, along with a little cleanup, the singleton/emptySet stuff happened. I checked this PR, ignoring the emptySet/singleton changes.

Then the change to get rid of the emptySet/singleton changes. I reviewed this change to insure that only singleton/emptySet stuff was changed. In addition to those changes, did find around 5 more changes for HashSet --> EnumSet, sigh. @tbw777, it's not unusual for there to be follow on PRs to clean up a few things, missed or otherwise, in a large PR as needed, rather than modifying a huge PR.

Now to verify that all the singleton/emptySet were reverted.

Pulled the PR, generated a diff, grep'd for "singleton" and "emptySet". Did not find any changes that included them (other than some white space).

So the commit looks OK to me. But I didn't start from scratch; another set of eyes...

(did find some unneeded changes, but I'm hesitant to point them out)

Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

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

Looked through it again and it looks good to me. The revert caused some trailing whitespace artifacts but this shouldn't hold this off I think.

Tests are green too so I am planning to merge this tomorrow in case someone still wants to take a look.

@mbien mbien removed the do not merge Don't merge this PR, it is not ready or just demonstration purposes. label Feb 6, 2023
@mbien
Copy link
Member

mbien commented Feb 6, 2023

Pulled the PR, generated a diff, grep'd for "singleton" and "emptySet". Did not find any changes that included them (other than some white space).

@errael here a trick (but don't tell anyone): just add .diff or .patch to get a diff/patch file
https://github.com/apache/netbeans/pull/5309.diff
https://github.com/apache/netbeans/pull/5309.patch

@errael
Copy link
Contributor

errael commented Feb 6, 2023

a trick (but don't tell anyone): just add .diff or .patch to get a diff/patch file

No matter how hard I try, I keep learning things about github. Thanks ;-)

@errael
Copy link
Contributor

errael commented Feb 6, 2023

@errael side answer smile please don't squash and merge. Both GitHub UI and CLI have (different) negative side effects there. Do agree that multiple commits can be better when kept during reviews though. PR branches are generally writable by committers as well as authors, so squashing and force pushing into the PR branch (where warranted) for final checks before merging is ideal IMO.

@neilcsmith-net I had always thought that references to CLI were about the git command. But I couldn't deny my ignorance anymore after reading what you said, yet another thing about git/github I didn't want to know.

So if I get this right, a pattern is to push several commits to a PR, then after approval, can squash locally (using mercurial in my case) and force push to the PR.

Does the compare button associated with a forced push after a local-squash/force-push show no changes (assuming, of course, that there were no changes)?

@neilcsmith-net
Copy link
Member

@neilcsmith-net I had always thought that references to CLI were about the git command.

@errael in that context it did! Any local squash and merge pushed directly to master causes its own set of issues. Gone a bit off topic! Can follow that up on dev@ if more info needed.

@mbien mbien dismissed BradWalker’s stale review February 7, 2023 02:12

resolved by PR author

@mbien
Copy link
Member

mbien commented Feb 7, 2023

no further comments, all green. merging. (removed old change request since it got resolved a while ago)

@mbien mbien merged commit 14b7e4b into apache:master Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:all-tests [ci] enable all tests Code cleanup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants