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

HashMap null key crashes program #7

Open
Erhannis opened this issue Oct 24, 2018 · 3 comments
Open

HashMap null key crashes program #7

Erhannis opened this issue Oct 24, 2018 · 3 comments

Comments

@Erhannis
Copy link

From what I can infer, HashMaps are replaced at runtime by a custom implementation, probably for better logging. However, it fails to account for null keys (which are valid for HashMaps, and not for the Hashtables, though I'm not certain if a true Hashtable is used anywhere). The following is a (slightly anonymized) stack trace:

.Debugger com.myprogram.Main
ODB: 28.Mar.07
ODB: Reading .debuggerDefaults file...
In target program2:
class com.myprogram.Main.main threw java.lang.NullPointerException
java.lang.NullPointerException
        at com.lambda.Debugger.Shadow.hashtablePut(Shadow.java:1977)
        at com.lambda.Debugger.D.hashMapPut(D.java:683)
        at com.lambda.Debugger.MyHashMap.put(MyHashMap.java:30)
        at com.myprogram.Main.main(Main.java:66)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.lambda.Debugger.Debugger.runTarget(Debugger.java:1141)
        at com.lambda.Debugger.Debugger$1.run(Debugger.java:1199)
        at java.lang.Thread.run(Thread.java:748)
ODB: 28.Mar.07 run complete.

The relevant lines of code in Main.main() would be:

HashMap<Integer, Integer> blah = new HashMap<>();
blah.put(5, 6);
blah.put(null, 1);
blah.put(7, 8);

which would crash on the third line, the one with a null key.

I'm attempting to fix the bug, but depending on how deep the rabbit hole goes, I may not make it.

@madhephaestus
Copy link
Member

@BilLewis may be able to help, Bil?

@Erhannis
Copy link
Author

I THINK I've fixed it, but it could be the case that there's some obscure functionality I've broken. Basically I replaced the two key.equals(k) in Shadow.java with Object.equals(key, k). It looks like it should work, and it appears to BE working, so maybe it's actually working. I'll try to make a pull request or something, later tonight.

@madhephaestus
Copy link
Member

thats great! I would love to see this project get picked up and modernized :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants