{"record":{"id":"fcae2fcb1d4954f3","repo":"clojure/clojure","slug":"unknown-collection-type","errorCode":null,"errorMessage":"Unknown Collection type","messagePattern":"Unknown Collection type","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/jvm/clojure/lang/Compiler.java","lineNumber":3499,"sourceCode":"\tpublic EmptyExpr(Object coll){\n\t\tthis.coll = coll;\n\t}\n\n\tpublic Object eval() {\n\t\treturn coll;\n\t}\n\n\tpublic void emit(C context, ObjExpr objx, GeneratorAdapter gen){\n\t\tif(coll instanceof IPersistentList)\n\t\t\tgen.getStatic(LIST_TYPE, \"EMPTY\", EMPTY_LIST_TYPE);\n\t\telse if(coll instanceof IPersistentVector)\n\t\t\tgen.getStatic(VECTOR_TYPE, \"EMPTY\", VECTOR_TYPE);\n\t\telse if(coll instanceof IPersistentMap)\n\t\t\t\tgen.getStatic(HASHMAP_TYPE, \"EMPTY\", HASHMAP_TYPE);\n\t\t\telse if(coll instanceof IPersistentSet)\n\t\t\t\t\tgen.getStatic(HASHSET_TYPE, \"EMPTY\", HASHSET_TYPE);\n\t\t\t\telse\n\t\t\t\t\tthrow new UnsupportedOperationException(\"Unknown Collection type\");\n\t\tif(context == C.STATEMENT)\n\t\t\t{\n\t\t\tgen.pop();\n\t\t\t}\n\t}\n\n\tpublic boolean hasJavaClass() {\n\t\treturn true;\n\t}\n\n\tpublic Class getJavaClass() {\n\t\tif(coll instanceof IPersistentList)\n\t\t\treturn IPersistentList.class;\n\t\telse if(coll instanceof IPersistentVector)\n\t\t\treturn IPersistentVector.class;\n\t\telse if(coll instanceof IPersistentMap)\n\t\t\t\treturn IPersistentMap.class;\n\t\t\telse if(coll instanceof IPersistentSet)","sourceCodeStart":3481,"sourceCodeEnd":3517,"githubUrl":"https://github.com/clojure/clojure/blob/f3b143341d6efc6428b523b2eaa099a6cc99156e/src/jvm/clojure/lang/Compiler.java#L3481-L3517","documentation":"Compiler.emitConstantsAsStatic or a similar emit path throws this UnsupportedOperationException when emitting a constant collection literal it cannot map to a known collection interface. The Clojure compiler only knows how to emit constants for vectors (IPersistentVector), maps (IPersistentMap), and sets (IPersistentSet); any other Collection subtype falls into the final else and throws. It indicates an internal compiler gap, not user code error, unless custom collection types are involved.","triggerScenarios":"A constant expression whose value is a Collection that is not an IPersistentVector, IPersistentMap, or IPersistentSet is emitted at compile time — e.g. via a custom IPersistentCollection implementation, a macro returning an exotic collection, or a data reader producing one.","commonSituations":"Using custom transient/record-like collections as compile-time constants; data readers (e.g. custom tagged literals) returning non-standard collection types that end up in constants; unusual interop objects embedded via macros.","solutions":["Ensure the compile-time constant value is one of the supported types: vector, map, or set (e.g. wrap with (vec coll) or (into {} ...))","Check custom data readers/macro return values and normalize them to core collections","If implementing a custom IPersistentCollection, add support in the compiler or avoid it in constant position","File/inspect upstream issue since this is an internal invariant violation in clojure.lang.Compiler"],"exampleFix":"// before: custom collection as constant\n(def c (MyCustomColl. [1 2 3]))\n// after: normalize to a core vector\n(def c (vec (MyCustomColl. [1 2 3])))","handlingStrategy":"type-guard","validationCode":"(defn supported-constant? [c]\n  (or (vector? c) (map? c) (set? c)))\n;; normalize before using as compile-time constant\n(when-not (supported-constant? c) (throw (ex-info \"unsupported constant coll\" {:v c})))","typeGuard":"(defn ->supported-coll [c]\n  (cond (vector? c) c (map? c) c (set? c) c :else (vec c)))","tryCatchPattern":"(try\n  (compile-or-load ns)\n  (catch UnsupportedOperationException e\n    (when-not (re-find #\"Unknown Collection type\" (.getMessage e)) (throw e))\n    (log/warn \"unsupported constant collection in compiled ns\")))","preventionTips":["Use only core vectors/maps/sets in constant positions","Normalize data-reader outputs to core collections","Test AOT compilation of all namespaces in CI","Avoid custom IPersistentCollection implementations unless the compiler is patched"],"tags":["clojure","compiler","unsupported-collection"],"backgroundTag":"unsupported-operation","analyzedSha":"f3b143341d6efc6428b523b2eaa099a6cc99156e","analyzedAt":"2026-09-09T12:04:58.961Z","contentChangedAt":"2026-09-09T12:04:58.961Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}