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

Fix #3707: javalib Inet6Address#hashCode is now more robust to null hostnames #3709

Merged

Conversation

LeeTibbert
Copy link
Contributor

@LeeTibbert LeeTibbert commented Jan 24, 2024

Fix #3707:

javalib Inet6Address#hashCode is now more robust to null hostnames.

@LeeTibbert LeeTibbert added component:javalib backport candidate PR which might be backported into previous major release of SN labels Jan 24, 2024
@LeeTibbert LeeTibbert changed the title Fix #3707: javalib Inet6Address#hashCode is now more robust to null hostnames Fix #3705: javalib Inet6Address#hashCode is now more robust to null hostnames Jan 24, 2024
@LeeTibbert LeeTibbert changed the title Fix #3705: javalib Inet6Address#hashCode is now more robust to null hostnames Fix #3707: javalib Inet6Address#hashCode is now more robust to null hostnames Jan 24, 2024
@LeeTibbert
Copy link
Contributor Author

I believe this PR is ready for review.

As per usual, I reviewed the logs of the failing tests. Those failures are the usual suspects.

Copy link
Contributor

@He-Pin He-Pin left a comment

Choose a reason for hiding this comment

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

Lgtm

@@ -45,7 +45,8 @@ final class Inet6Address private (
override def hashCode(): Int = {
var res = 1
res = 31 * res + ju.Arrays.hashCode(ipAddress)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ipaddress can be null too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Thank you.

It is not evident to a reviewer and certainly not to me when I wrote it, but ju.Arrays.hashCode(null)
always returns 0. That is both robust sensible.

I added a comment to remind myself and others who try to verify that method in the future.
A runtime test would have been the alternative. I went with a comment to save a few cpu
cycles when run.

Dratted nulls!

@LeeTibbert
Copy link
Contributor Author

I believe this PR is ready for review.

As is my practice, I examined the log files of the tests which have completed as of the end
of this sprint: usual offenders.

@WojciechMazur WojciechMazur merged commit 2a23a43 into scala-native:main Jan 26, 2024
55 of 62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport candidate PR which might be backported into previous major release of SN component:javalib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

java.net.Inet6Address hashCode method should be robust to null hostnames
3 participants