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

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.
Hide
Stuart Halloway added a comment -

waiting on Stuart's patch tweak

Show
Stuart Halloway added a comment - waiting on Stuart's patch tweak
Hide
Stuart Sierra added a comment -

Oops. Sorry. Will fix.

Show
Stuart Sierra added a comment - Oops. Sorry. Will fix.
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 -

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

looks ok at first glance

Show
Rich Hickey added a comment - looks ok at first glance
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?
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.
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()
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
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?

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: