Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Below, three objects are put into
options
. Constructor ofHashMap
which takes anint
is a bit confusing, and this change won't guarantee prevention of rehashing, as the description of the PR claims. The misleading constructor ofHashMap
is described in detail in https://bugs.openjdk.org/browse/JDK-8284377.JDK-8284377 was released in Java 19, so it is not yet accessible to JavaCC due to max version limited to Java 8 (see README). A more correct way of calculating capacity for a pre-sized
HashMap
in Java versions before Java 19 isnumberOfElements / 0.75
, where 0.75 is the default load factor. See, for example, change for JDK-8284377 in HostLocaleProviderAdapterImpl.java.In this particular case,
3 / 0.75 == 4
, although other places in code of JDK also add1
on top of that: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.
@rybak how did you find this issue? (It's probably not worth changing again since the impact is negligible, though it's good to know about the discrepancy.)
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've found out about JDK-8284377 online – it was used as an example of a fairly fast contribution to JDK from a new contributor. It took less than a month between PR open and merge, and it included a CSR, which is a big deal, apparently. I stumbled upon it either on Twitter or the Inside Java podcast.
As for
JavaccPlugin.java
– I was reading the source of the plugin for $dayjob purposes. The exact reason is offtopic for this PR, but I might come back with a question in form of a new GitHub issue, or even a PR to improve docs, if it will be applicable.