Clojure

NPE calling keyword on map from bean

Details

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

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

Activity

Hide
Stuart Halloway added a comment -

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

Show
Stuart Halloway added a comment - Bean needs a full overhaul. In my ideal world it would be deprecated out of core into some other namespace.
Hide
Luc Préfontaine added a comment -

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.

Show
Luc Préfontaine added a comment - 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.
Hide
Steve Miner added a comment - - edited

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.

Show
Steve Miner added a comment - - edited 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.

People

Vote (2)
Watch (5)

Dates

  • Created:
    Updated:
    Resolved: