Clojure

data-reader returning nil causes exception

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.4, Release 1.5, Release 1.6, Release 1.7, Release 1.8
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Environment:
    clojure 1.5 beta2, Mac OS X 10.8.2, java version "1.6.0_37"
  • Patch:
    Code and Test
  • Approval:
    Triaged

Description

If a data-reader returns nil, the reader throws java.lang.RuntimeException: No dispatch macro... The error message implies that there is no dispatch macro for whatever the first character of the tag happens to be.

Here's a simple example:

user=> (binding [*data-readers* {'f/ignore (constantly nil)}] 
         (read-string "#f/ignore 42 10"))
RuntimeException No dispatch macro for: f  clojure.lang.Util.runtimeException (Util.java:219)

The original reader code did not distinguish between the absence of a data-reader and a returned value of nil from the appropriate data-reader. It therefore got confused and tried to find a dispatch macro, sending it further down the incorrect code path, ultimately yielding a misleading error message.

The original documentation did not distinguish nil as an illegal value. Clearly this bug was an oversight in the original data-reader code, not an intentional feature.

The patch uses a sentinel value to distinguish the missing data-reader case from the nil returned value case.

Patch: clj-1139-2.patch

Activity

Steve Miner made changes -
Field Original Value New Value
Attachment clj-1138-allow-data-reader-to-return-nil-instead-of-throwing.patch [ 11773 ]
Steve Miner made changes -
Labels reader patch reader
Steve Miner made changes -
Patch Code and Test [ 10002 ]
Steve Miner made changes -
Attachment clj-1138-data-reader-return-nil-for-no-op.patch [ 11774 ]
Steve Miner made changes -
Attachment clj-1138-allow-data-reader-to-return-nil-instead-of-throwing.patch [ 11773 ]
Steve Miner made changes -
Attachment clj-1138-data-reader-return-nil-for-no-op.patch [ 11774 ]
Steve Miner made changes -
Patch Code and Test [ 10002 ]
Steve Miner made changes -
Labels patch reader reader
Nicola Mometto made changes -
Affects Version/s Release 1.7 [ 10250 ]
Affects Version/s Release 1.6 [ 10157 ]
Affects Version/s Release 1.8 [ 10254 ]
Patch Code and Test [ 10002 ]
Nicola Mometto made changes -
Alex Miller made changes -
Approval Triaged [ 10120 ]
Alex Miller made changes -
Description If a data-reader returns nil, the reader throws java.lang.RuntimeException: No dispatch macro... The error message implies that there is no dispatch macro for whatever the first character of the tag happens to be.

Here's a simple example:

    (binding [*data-readers* {'f/ignore (constantly nil)}] (read-string "#f/ignore 42 10"))

RuntimeException No dispatch macro for: f clojure.lang.Util.runtimeException (Util.java:219)
If a data-reader returns nil, the reader throws java.lang.RuntimeException: No dispatch macro... The error message implies that there is no dispatch macro for whatever the first character of the tag happens to be.

Here's a simple example:

{code}
user=> (binding [*data-readers* {'f/ignore (constantly nil)}] (read-string "#f/ignore 42 10"))
RuntimeException No dispatch macro for: f clojure.lang.Util.runtimeException (Util.java:219)
{code}

*Patch:* clj-1139-2.patch
Attachment clj-1139-2.patch [ 16490 ]
Alex Miller made changes -
Description If a data-reader returns nil, the reader throws java.lang.RuntimeException: No dispatch macro... The error message implies that there is no dispatch macro for whatever the first character of the tag happens to be.

Here's a simple example:

{code}
user=> (binding [*data-readers* {'f/ignore (constantly nil)}] (read-string "#f/ignore 42 10"))
RuntimeException No dispatch macro for: f clojure.lang.Util.runtimeException (Util.java:219)
{code}

*Patch:* clj-1139-2.patch
If a data-reader returns nil, the reader throws java.lang.RuntimeException: No dispatch macro... The error message implies that there is no dispatch macro for whatever the first character of the tag happens to be.

Here's a simple example:

{code}
user=> (binding [*data-readers* {'f/ignore (constantly nil)}]
         (read-string "#f/ignore 42 10"))
RuntimeException No dispatch macro for: f clojure.lang.Util.runtimeException (Util.java:219)
{code}

*Patch:* clj-1139-2.patch
Steve Miner made changes -
Description If a data-reader returns nil, the reader throws java.lang.RuntimeException: No dispatch macro... The error message implies that there is no dispatch macro for whatever the first character of the tag happens to be.

Here's a simple example:

{code}
user=> (binding [*data-readers* {'f/ignore (constantly nil)}]
         (read-string "#f/ignore 42 10"))
RuntimeException No dispatch macro for: f clojure.lang.Util.runtimeException (Util.java:219)
{code}

*Patch:* clj-1139-2.patch
If a data-reader returns nil, the reader throws java.lang.RuntimeException: No dispatch macro... The error message implies that there is no dispatch macro for whatever the first character of the tag happens to be.

Here's a simple example:

{code}
user=> (binding [*data-readers* {'f/ignore (constantly nil)}]
         (read-string "#f/ignore 42 10"))
RuntimeException No dispatch macro for: f clojure.lang.Util.runtimeException (Util.java:219)
{code}

The original reader code did not distinguish between the absence of a data-reader and a returned value of nil from the appropriate data-reader. It therefore got confused and tried to find a dispatch macro, sending it further down the incorrect code path, ultimately yielding a misleading error message.

The original documentation did not distinguish nil as an illegal value. Clearly this bug was an oversight in the original data-reader code, not an intentional feature.

The patch uses a sentinel value to distinguish the missing data-reader case from the nil returned value case.

*Patch:* clj-1139-2.patch

People

Vote (2)
Watch (2)

Dates

  • Created:
    Updated: