Clojure

case gives NPE when used with nil

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.2
  • Fix Version/s: Release 1.3
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

This code gives a NullPointerException:

(case nil
nil "foo")

If fixing this is impossible for implementation reasons, at least the documentation and error messages should be improved.

Activity

Rich Hickey made changes -
Field Original Value New Value
Fix Version/s Release.Next [ 10038 ]
Approval Vetted
Hide
Aaron Bedra added a comment -

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?

Show
Aaron Bedra added a comment - 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?
Aaron Bedra made changes -
Waiting On richhickey
Hide
a_strange_guy added a comment -

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.

Show
a_strange_guy added a comment - 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.
Hide
Rich Hickey added a comment -

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()

Show
Rich Hickey added a comment - 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()
Rich Hickey made changes -
Waiting On richhickey
Hide
Aaron Bedra added a comment -

Thanks Rich. I will take this one and get a patch in hopefully today.

Show
Aaron Bedra added a comment - Thanks Rich. I will take this one and get a patch in hopefully today.
Aaron Bedra made changes -
Assignee Aaron Bedra [ aaron ]
Hide
Aaron Bedra added a comment -

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?

Show
Aaron Bedra added a comment - 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?
Aaron Bedra made changes -
Attachment 0702-fix-npe-in-nil-case.patch [ 10072 ]
Approval Vetted Test
Aaron Bedra made changes -
Waiting On richhickey
Hide
Rich Hickey added a comment -

looks ok at first glance

Show
Rich Hickey added a comment - looks ok at first glance
Rich Hickey made changes -
Waiting On richhickey
Fogus made changes -
Patch Code
Hide
Stuart Sierra added a comment -

New patch 0702-fix-npe-in-nil-case-2.patch.gz adds a test.

Show
Stuart Sierra added a comment - New patch 0702-fix-npe-in-nil-case-2.patch.gz adds a test.
Stuart Sierra made changes -
Attachment 0702-fix-npe-in-nil-case-2.patch.gz [ 10087 ]
Patch Code Code and Test
Hide
Aaron Bedra added a comment -

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.

Show
Aaron Bedra added a comment - 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.
Hide
Stuart Sierra added a comment -

Oops. Sorry. Will fix.

Show
Stuart Sierra added a comment - Oops. Sorry. Will fix.
Stuart Sierra made changes -
Assignee Aaron Bedra [ aaron ] Stuart Sierra [ stuart.sierra ]
Hide
Stuart Halloway added a comment -

waiting on Stuart's patch tweak

Show
Stuart Halloway added a comment - waiting on Stuart's patch tweak
Stuart Halloway made changes -
Approval Test Incomplete
Aaron Bedra made changes -
Waiting On stuart.sierra
Hide
Stuart Sierra added a comment -

Patch 0702-fix-npe-in-nil-case-3.patch.gz replaces previous patches, but preserves correct commit messages and authors.

Show
Stuart Sierra added a comment - Patch 0702-fix-npe-in-nil-case-3.patch.gz replaces previous patches, but preserves correct commit messages and authors.
Stuart Sierra made changes -
Assignee Stuart Sierra [ stuart.sierra ]
Attachment 0702-fix-npe-in-nil-case-3.patch.gz [ 10097 ]
Approval Incomplete Test
Waiting On stuart.sierra
Stuart Halloway made changes -
Approval Test Screened
Rich Hickey made changes -
Approval Screened Ok
Stuart Halloway made changes -
Status Open [ 1 ] Closed [ 6 ]
Resolution Completed [ 1 ]

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: