# Nil value in heterogeneous tuple throws a NullPointerException

**URL:** <https://forum.datomic.com/t/nil-value-in-heterogeneous-tuple-throws-a-nullpointerexception/1693>\
**Category:** Datomic Cloud\
**Created:** [November 19, 2020, 9:34pm UTC](https://forum.datomic.com/t/nil-value-in-heterogeneous-tuple-throws-a-nullpointerexception/1693 "2020-11-19T21:34:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshkh](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/joshkh/32/355_2.png) [@joshkh](https://forum.datomic.com/u/joshkh)\
**Post date:** [November 19, 2020, 9:34pm UTC](https://forum.datomic.com/t/nil-value-in-heterogeneous-tuple-throws-a-nullpointerexception/1693/1 "2020-11-19T21:34:56Z")

</div>

`nil` is a valid heterogeneous tuple value, right?

> [@Tuple with single item fails transaction](https://forum.datomic.com/t/tuple-with-single-item-fails-transaction/1690/2):
>
> Additionally you may be interested in knowing that, `nil` is a legal value for any slot in a tuple. This facilitates using tuples in range searches, where `nil` sorts lowest.  
> – [Tuple with single item fails transaction](https://forum.datomic.com/t/tuple-with-single-item-fails-transaction/1690)

Given the following schema:

```clojure
{:db/ident :person/name
 :db/valueType :db.type/string
 :db/cardinality :db.cardinality/one}

{:db/ident :person/parents
 :db/valueType :db.type/tuple
 :db/tupleTypes [:db.type/ref :db.type/ref]
 :db/cardinality :db.cardinality/one}

```

I can happily transact:

```clojure
{:tx-data [{:db/id "child"
            :person/name "child"
            :person/parents ["parent-a" nil]}]}
=> Success

```

And happily pull the result:

```clojure
(d/q '{:find [(pull ?p [*])]
       :in [$]
       :where [[?p :person/name "child"]]}
     db) 

=> [[{:db/id 101155069755487
      :person/name "child"
      :person/parents [101155069755485 nil]}]]

```

However, when attempting to `untuple` the tuple values and bind to their values, the binding to the `nil` value throws a NullPointerException:

```clojure
(d/q '{:find [?person ?parent-a-name ?parent-b-name]
       :in [$]
       :where [[?person :person/name "child"]
               [?person :person/parents ?parents-tuple]
               [(untuple ?parents-tuple) [?parent-a ?parent-b]]
               [?parent-a :person/name ?parent-a-name]
               [?parent-b :person/name ?parent-b-name] ;<-- adding this throws exception
               ]}
     db)

```

```plaintext
Execution error (NullPointerException) at datomic.core.db/asserting-datum (db.clj:-1).
null
clojure.lang.ExceptionInfo: processing clause: [?parent-b :person/name ?parent-b-name], message: #:cognitect.anomalies{:category :cognitect.anomalies/incorrect, :message "processing clause: [?parent-b :person/name ?parent-b-name], message: "}
	at datomic.core.datalog$throw_query_ex_BANG_.invokeStatic(datalog.clj:50)
java.lang.NullPointerException

```

Is this expected? Thanks!
