Clojure

bean throws NPE when key doesn't exist

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: Release 1.3
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test

Description

The result of (bean obj) throws a NullPointerException when passed in a key that doen't exist. I think instead it should return nil to be consistent with maps and records - or at least the error message should be more explicit.

Activity

Hide
Alexander Redington added a comment -

The proxy returned by (bean) performs a bare invocation on the getter method without checking if it exists first. Fixed the bug by adding a long-hand constantly as the missing value for the map fetch. (constantly is not defined yet when core_proxy is read.)

Also renamed the property map defined in bean to 'propmap' instead of 'pmap' to avoid ambiguity with clojure.core/pmap

Show
Alexander Redington added a comment - The proxy returned by (bean) performs a bare invocation on the getter method without checking if it exists first. Fixed the bug by adding a long-hand constantly as the missing value for the map fetch. (constantly is not defined yet when core_proxy is read.) Also renamed the property map defined in bean to 'propmap' instead of 'pmap' to avoid ambiguity with clojure.core/pmap
Hide
Stuart Halloway added a comment -

Beans aren't maps, and without any discussion of motivation it isn't clear that this change is an improvement.

If bean was more consumer-friendly, people might use it in production more often. Don't. Reflection is slow. If there is a motivating use case other than REPL exploration for converting beans to maps, let's design something more performant targeted to that case.

Show
Stuart Halloway added a comment - Beans aren't maps, and without any discussion of motivation it isn't clear that this change is an improvement. If bean was more consumer-friendly, people might use it in production more often. Don't. Reflection is slow. If there is a motivating use case other than REPL exploration for converting beans to maps, let's design something more performant targeted to that case.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: