<< Back to previous view

[CLJ-724] bean throws NPE when key doesn't exist Created: 22/Jan/11  Updated: 05/Apr/11  Resolved: 05/Apr/11

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.3
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Benjamin Teuber Assignee: Unassigned
Resolution: Declined Votes: 0
Labels: None

Attachments: File clj-724.diff    
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.



 Comments   
Comment by Alexander Redington [ 25/Mar/11 9:51 AM ]

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

Comment by Stuart Halloway [ 05/Apr/11 8:46 PM ]

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.

Generated at Wed Jul 23 16:43:53 CDT 2014 using JIRA 4.4#649-r158309.