<< Back to previous view

[CLJCLR-74] pprint throws exception on very specific input Created: 22/Aug/15  Updated: 27/Nov/15  Resolved: 27/Nov/15

Status: Resolved
Project: ClojureCLR
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Cees van Kemenade Assignee: David Miller
Resolution: Completed Votes: 0
Labels: None

clojure-clr 1.5 and 1.7

Attachments: Text File Ref.patch    


I have observed an input-dependent bug in the pprint function of clojure-clr. The bug is triggered in my clojure-clr version 1.5 and 1.7 on the next, fairly minimal example.

user=> (pprint [ ["spec"] ["naamZorgverlener"] ["AGBZorg"] ["email"] ["normalized" :normInstelling]])
user=> NullReferenceException Object reference not set to an instance of an obj
ect. clojure.lang.Ref.Equals (d:\work\clojure-clr\Clojure\Clojure\Lib\Ref.cs:70

Small changes to the data, make the error disappear, for example

1. Increase the length of the string "spec" to "spec_12345" ("spec_1234" still produces an NullReference exception)

user=> (pprint [ ["spec_12345"] ["naamZorgverlener"] ["AGBZorg"] ["email"] ["normalized" :normInstelling]])
["normalized" :normInstelling]]

2. removing the element ["email"]

user=> (pprint [ ["spec_12345"] ["naamZorgverlener"] ["AGBZorg"] ["normalized" :normInstelling]])
["normalized" :normInstelling]]

I was not able to reproduce this pprint-bug in clojure 1.7 for java.

Comment by Jeremy R Sellars [ 21/Nov/15 6:30 PM ]

The exception comes from clojure.lang.Ref.Equals when comparing a ref to null. There are two problems in the equality checking and comparison for Refs. (IComparable.CompareTo is supposed to support CompareTo(null), according to https://msdn.microsoft.com/en-us/library/system.icomparable.compareto(v=vs.110).aspx). That seems to be the root problem. The other affected methods delegated to CompareTo even when comparing against null, which was probably unintentional. The use of ReferenceEquals clarifies the intent.

I am attaching a patch with C# tests. This worked (built on Windows, .net 3.5 & 4.0). I did not test Mono or Linux, although this did not seem to be a platform-specific problem.

I did not look into the pprint code because the C# changes fixed the problem.

(I signed to contributor agreement today before submitting the patch.)

Comment by David Miller [ 27/Nov/15 10:47 AM ]


Per the Clojure contribution rules, I can accept patches only from those who have signed a Contributor Agreement for Clojure. See http://clojure.org/contributing .

In this case, I think I can figure out a fix based on your observations.


Comment by David Miller [ 27/Nov/15 11:09 AM ]

Fix to Ref.CompareTo resolves the error.
Commit 07527db, 2015.11.27

Generated at Mon Nov 30 16:39:41 CST 2015 using JIRA 4.4#649-r158309.