-
Notifications
You must be signed in to change notification settings - Fork 1k
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
IntObjectHashMap.values().toArray() method throws ClassCastException #13761
Comments
Has this issue been approved or followed up? I've been testing with this example and also noted a few things:
I'm not that familiar with Java tricks yet, and I would like to research a little bit more on this and make a PR |
This is indeed a bug. I'm not sure how it got introduced because toArray would return Object[] in HPPC - it only changes to a an array of primitives if the type is primitive:
I also compared the code in Lucene with that in HPPC and I see some manual changes there. @bruno-roustant - I guess you ported this partially manually? I wonder if it'd be possible to create a port automatically or at least semi-automatically so that the code doesn't diverge too much from HPPC? |
@BrianWoolfolk - (1) it's because of something called type erasure. All the VType types inside toArray are replaced with an Object. Externally, the compiler is mislead to think it'll return a String[] but it is in fact an Object[] instance (which is a different type). (2) associative arrays have the freedom of ordering their elements in any way you like (unless the order is explicitly preserved, like with LinkedHashMap, but this is not the case here). This method should have the return type of Object[]. Alternatively, it could be removed entirely since it's already an Iterable so for-type loops will work perfectly well. |
@dweiss it is a bit old in my memory, but I remember I had to diverge a bit to avoid taking too many classes from HPPC by dependency. I see that you assigned it to you, and I can take it or help if you don't have time. Thanks |
Sure, no problem at all! I'll handle this issue and I have a side note to check and see if we can make the port more aligned with HPPC code. |
Thank you for reporting the problem, @bugmakerrrrrr |
@dweiss I think that |
Description
The ClassCastEx is thrown when the
IntObjectHashMap.values().toArray()
method is called with a type other thanObject
, and of course the same exception occurs withCharObjectHashMap
andLongObjectHashMap
. The issue can be reproduced with the following test.There are several options to fix the issue.
Object[]
;ArrayList.toArray(T[])
method to pass aT[]
parameter;toArray
method with aasList
method, and return aList<T>
.IMO, either option 2 or 3 would be acceptable. Any thought?
Version and environment details
No response
The text was updated successfully, but these errors were encountered: