Last active
August 29, 2015 14:13
-
-
Save MichaelBlume/735c8f601210cfa1ecaf to your computer and use it in GitHub Desktop.
debug NPE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git i/src/clj/clojure/core_deftype.clj w/src/clj/clojure/core_deftype.clj | |
index 97e14cc..eb98de8 100644 | |
--- i/src/clj/clojure/core_deftype.clj | |
+++ w/src/clj/clojure/core_deftype.clj | |
@@ -50,6 +50,18 @@ | |
(drop-while seq? (next s))) | |
ret))) | |
+(comment | |
+ (map deref | |
+ (into [] | |
+ (for [i (range 20)] | |
+ (future | |
+ (dotimes [i 1000000] | |
+ (when (-> nil set (disj 'Object 'java.lang.Object) vec seq) | |
+ (throw (Exception.))))))))) | |
+ | |
+(defn- spy [x] | |
+ (println "calling set with:" x) x) | |
+ | |
(defn- parse-opts+specs [opts+specs] | |
(let [[opts specs] (parse-opts opts+specs) | |
impls (parse-impls specs) | |
@@ -57,6 +69,8 @@ | |
(:on (deref (resolve %))) | |
%) | |
(keys impls)) | |
+ seq | |
+ spy | |
set | |
(disj 'Object 'java.lang.Object) | |
vec) | |
diff --git i/src/jvm/clojure/lang/PersistentVector.java w/src/jvm/clojure/lang/PersistentVector.java | |
index 9804a0b..e54a5a1 100644 | |
--- i/src/jvm/clojure/lang/PersistentVector.java | |
+++ w/src/jvm/clojure/lang/PersistentVector.java | |
@@ -102,7 +102,20 @@ static public PersistentVector create(Iterable items){ | |
TransientVector ret = EMPTY.asTransient(); | |
while(iter.hasNext()) | |
ret = ret.conj(iter.next()); | |
- return ret.persistent(); | |
+ PersistentVector retP = ret.persistent(); | |
+ if (retP.count() != RT.count(items)) { | |
+ IFn println = RT.var("clojure.core", "println"); | |
+ println.invoke("items:", items); | |
+ println.invoke("items class:", items.getClass().getName()); | |
+ println.invoke("returned vector:", retP); | |
+ println.invoke("same as empty:" , items == PersistentHashSet.EMPTY); | |
+ // Prevent debug output getting munged with traceback | |
+ try { | |
+ Thread.sleep(200); | |
+ } catch (InterruptedException e) {} | |
+ Util.sneakyThrow(new Exception("PersistentVector too long")); | |
[19:08][michael.blume@tcc-michael-4:~/workspace/clojure((3e7cb1a...) *)]$ g d | cat | |
diff --git i/src/clj/clojure/core_deftype.clj w/src/clj/clojure/core_deftype.clj | |
index 97e14cc..eb98de8 100644 | |
--- i/src/clj/clojure/core_deftype.clj | |
+++ w/src/clj/clojure/core_deftype.clj | |
@@ -50,6 +50,18 @@ | |
(drop-while seq? (next s))) | |
ret))) | |
+(comment | |
+ (map deref | |
+ (into [] | |
+ (for [i (range 20)] | |
+ (future | |
+ (dotimes [i 1000000] | |
+ (when (-> nil set (disj 'Object 'java.lang.Object) vec seq) | |
+ (throw (Exception.))))))))) | |
+ | |
+(defn- spy [x] | |
+ (println "calling set with:" x) x) | |
+ | |
(defn- parse-opts+specs [opts+specs] | |
(let [[opts specs] (parse-opts opts+specs) | |
impls (parse-impls specs) | |
@@ -57,6 +69,8 @@ | |
(:on (deref (resolve %))) | |
%) | |
(keys impls)) | |
+ seq | |
+ spy | |
set | |
(disj 'Object 'java.lang.Object) | |
vec) | |
diff --git i/src/jvm/clojure/lang/PersistentVector.java w/src/jvm/clojure/lang/PersistentVector.java | |
index 9804a0b..e54a5a1 100644 | |
--- i/src/jvm/clojure/lang/PersistentVector.java | |
+++ w/src/jvm/clojure/lang/PersistentVector.java | |
@@ -102,7 +102,20 @@ static public PersistentVector create(Iterable items){ | |
TransientVector ret = EMPTY.asTransient(); | |
while(iter.hasNext()) | |
ret = ret.conj(iter.next()); | |
- return ret.persistent(); | |
+ PersistentVector retP = ret.persistent(); | |
+ if (retP.count() != RT.count(items)) { | |
+ IFn println = RT.var("clojure.core", "println"); | |
+ println.invoke("items:", items); | |
+ println.invoke("items class:", items.getClass().getName()); | |
+ println.invoke("returned vector:", retP); | |
+ println.invoke("same as empty:" , items == PersistentHashSet.EMPTY); | |
+ // Prevent debug output getting munged with traceback | |
+ try { | |
+ Thread.sleep(200); | |
+ } catch (InterruptedException e) {} | |
+ Util.sneakyThrow(new Exception("PersistentVector too long")); | |
+ } | |
+ return retP; | |
} | |
static public PersistentVector create(Object... items){ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment