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

Use another hash code for projects #734

Merged
merged 2 commits into from
Nov 23, 2018
Merged

Use another hash code for projects #734

merged 2 commits into from
Nov 23, 2018

Conversation

jvican
Copy link
Contributor

@jvican jvican commented Nov 23, 2018

The previous hashCode of Project was using the hash of the
serialized file. At the time of doing that, I did not realize the use
case that this commit fixes would be affected.

We're now using a unique ID composed of the name and the configuration
path a file comes from. Whenever that is different, it must be a
different project.

Fixes #733

@jvican jvican added bug A defect or misbehaviour. task / compile ergonomics Any change that affects developer ergonomics and the easiness of use of bloop. labels Nov 23, 2018
@@ -59,7 +59,8 @@ final case class Project(
}

override def toString: String = s"$name"
override val hashCode: Int = origin.hash
val uniqueId = s"${origin.path}#${name}"
override val hashCode: Int = uniqueId.hashCode
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a change of this PR, but are you sure you want to rely on hashCode to test for equality just below? String hash code in Java can collide sometimes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Object.hashCode isn't really a crypto secure hash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in the latest commit, the likelihood of this happening is quite small for us because at max we'll only have 200 projects in one bloop server, but it's nonetheless good advice and it's better be safe than sorry!

The previous `hashCode` of `Project` was using the hash of the
serialized file. At the time of doing that, I did not realize the use
case that this commit fixes would be affected.

We're now using a unique ID composed of the name and the configuration
path a file comes from. Whenever that is different, it must be a
different project.

We use `ByteHasher` instead of `hashCode` to avoid hash code collisions.
The probability of a hash code collision is very slow, especially
because the server should only have around 100 or 200 projects maximum,
but it's better be safe than sorry.

Fixes #733
@jvican jvican merged commit 4601df7 into master Nov 23, 2018
@tgodzik tgodzik deleted the ticket/733 branch September 7, 2021 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A defect or misbehaviour. ergonomics Any change that affects developer ergonomics and the easiness of use of bloop. task / compile
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't trigger recompilation if project configuration changes
2 participants