NPE calling keyword on map from bean

Description

Calling a keyword on a map returned from clojure.core/bean causes a null pointer exception if the keyword is not a key in the map:

user=> (:a (bean {}))
java.lang.NullPointerException (NO_SOURCE_FILE:0)
user=> (.printStackTrace *e)
Caused by: java.lang.NullPointerException
at clojure.core$bean$v__4765.invoke(core_proxy.clj:385)
at clojure.core$bean$fn__4786.invoke(core_proxy.clj:394)
at clojure.core.proxy$clojure.lang.APersistentMap$0.valAt(Unknown Source)
at clojure.lang.KeywordLookupSite.fault(KeywordLookupSite.java:33)
at user$eval1062.invoke(NO_SOURCE_FILE:7)
at clojure.lang.Compiler.eval(Compiler.java:5424)
... 9 more

The object returned by bean claims to be an APersistentMap FWIW:

user=> (class (bean {}))
clojure.core.proxy$clojure.lang.APersistentMap$0

Environment

None

Attachments

1

Activity

Show:

Steve Miner April 20, 2012 at 7:09 PM

The current work-around is to use a default arg like this:

(:a my-bean nil)

It works, but it's inconvenient and adds complexity to the handling of bean maps.

Normal maps of course already return nil as the default value for a missing key. The current bean proxy does the contains? check on the key only if there's a default value. The patch uses the same contains? check for the single-arg version of valAt.

Luc Préfontaine October 8, 2011 at 5:59 AM

If you can sketch a bit what you have in mind, I might give it a try.
I have some time available and went through the pending issues, this one seems within
my reach.

Stuart Halloway October 7, 2011 at 3:41 PM

Bean needs a full overhaul. In my ideal world it would be deprecated out of core into some other namespace.

Completed

Details

Assignee

Reporter

Approval

Ok

Patch

Code and Test

Priority

Affects versions

Fix versions

Created September 28, 2011 at 1:00 AM
Updated June 15, 2012 at 5:09 PM
Resolved June 15, 2012 at 5:09 PM