[CLJ-702] case gives NPE when used with nil Created: 04/Jan/11 Updated: 25/Feb/11 Resolved: 25/Feb/11 |
|
| Status: | Closed |
| Project: | Clojure |
| Component/s: | None |
| Affects Version/s: | Release 1.2 |
| Fix Version/s: | Release 1.3 |
| Type: | Defect | Priority: | Major |
| Reporter: | Benjamin Teuber | Assignee: | Unassigned |
| Resolution: | Completed | Votes: | 1 |
| Labels: | None | ||
| Attachments: |
|
| Patch: | Code and Test |
| Approval: | Ok |
| Description |
|
This code gives a NullPointerException: (case nil If fixing this is impossible for implementation reasons, at least the documentation and error messages should be improved. |
| Comments |
| Comment by Aaron Bedra [ 05/Jan/11 9:28 PM ] |
|
What would be the desired fix look like for this? Should this be a documentation update or should this be updated to not produce an NPE? |
| Comment by a_strange_guy [ 06/Jan/11 4:23 PM ] |
|
I think that the case macro should just generate a null check before calling hashcode on a value. The same way protocol functions automatically check for null before dispatching. |
| Comment by Rich Hickey [ 07/Jan/11 8:03 AM ] |
|
First step in fixing a problem is to understand it. The exception is thrown during compilation and the stack trace points to c.l.Compiler$ObjExpression.constantType() |
| Comment by Aaron Bedra [ 07/Jan/11 9:31 AM ] |
|
Thanks Rich. I will take this one and get a patch in hopefully today. |
| Comment by Aaron Bedra [ 07/Jan/11 2:17 PM ] |
|
Rich, this seems to solve the issue demonstrated in this ticket. I don't have full context on all possible impact points here. Can you please take a look at this and let me know if I missed anything? |
| Comment by Rich Hickey [ 10/Jan/11 6:35 AM ] |
|
looks ok at first glance |
| Comment by Stuart Sierra [ 21/Jan/11 1:44 PM ] |
|
New patch 0702-fix-npe-in-nil-case-2.patch.gz adds a test. |
| Comment by Aaron Bedra [ 25/Jan/11 7:48 AM ] |
|
Stuart, your patch replaces the original patch and the commit message doesn't reveal the intent of the fix. It also overwrites me as the original patch submitter. |
| Comment by Stuart Sierra [ 25/Jan/11 2:50 PM ] |
|
Oops. Sorry. Will fix. |
| Comment by Stuart Halloway [ 28/Jan/11 10:23 AM ] |
|
waiting on Stuart's patch tweak |
| Comment by Stuart Sierra [ 28/Jan/11 3:00 PM ] |
|
Patch 0702-fix-npe-in-nil-case-3.patch.gz replaces previous patches, but preserves correct commit messages and authors. |