{"record":{"id":"262c971378c01df1","repo":"ruby-concurrency/concurrent-ruby","slug":"cannot-enqueue-nil","errorCode":null,"errorMessage":"cannot enqueue nil","messagePattern":"cannot enqueue nil","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/concurrent-ruby/concurrent/collection/java_non_concurrent_priority_queue.rb","lineNumber":69,"sourceCode":"          @queue.size\n        end\n        alias_method :size, :length\n\n        # @!macro priority_queue_method_peek\n        def peek\n          @queue.peek\n        end\n\n        # @!macro priority_queue_method_pop\n        def pop\n          @queue.poll\n        end\n        alias_method :deq, :pop\n        alias_method :shift, :pop\n\n        # @!macro priority_queue_method_push\n        def push(item)\n          raise ArgumentError.new('cannot enqueue nil') if item.nil?\n          @queue.add(item)\n        end\n        alias_method :<<, :push\n        alias_method :enq, :push\n\n        # @!macro priority_queue_method_from_list\n        def self.from_list(list, opts = {})\n          queue = new(opts)\n          list.each{|item| queue << item }\n          queue\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":51,"sourceCodeEnd":85,"githubUrl":"https://github.com/ruby-concurrency/concurrent-ruby/blob/0b88d5ff75f69b3740c8f0868e76f833cb2fd45d/lib/concurrent-ruby/concurrent/collection/java_non_concurrent_priority_queue.rb#L51-L85","documentation":"This is the JRuby (java.util.PriorityQueue-backed) engine behind Concurrent::PriorityQueue. The heap uses nil as its sentinel for 'queue empty' (pop returns nil when nothing is dequeued), so a nil item would make a real entry indistinguishable from emptiness — push therefore rejects nil with ArgumentError.","triggerScenarios":"`queue.push(nil)`, `queue << nil`, or `queue.enq(nil)`; enqueueing `hash[key]` for a missing key; building the queue from a list containing nils (`from_list([1, nil, 2])` pushes each item, including the nil).","commonSituations":"Nulls from databases, config, or JSON parsed into scheduling queues; optional fields that end up nil; forgetting #compact on input arrays; using nil as a 'lowest priority' marker.","solutions":["Filter nils before enqueueing: `items.compact.each { |i| queue << i }`.","Use fetch with an explicit default instead of nil-producing lookups: `queue << config.fetch(:retry_after, DEFAULT)`.","Represent 'no value' with a sentinel object that implements <=> rather than nil.","Wrap items in a Struct carrying priority plus payload so nil payloads become legal values inside the wrapper."],"exampleFix":"// before\nqueue << config[:retry_after]   # nil when key missing -> ArgumentError\n\n// after\nqueue << config.fetch(:retry_after, DEFAULT_RETRY_AFTER)","handlingStrategy":"validation","validationCode":"queue << item unless item.nil?","typeGuard":"def enqueueable?(item)\n  !item.nil? && item.respond_to?(:<=>)\nend","tryCatchPattern":"begin\n  queue << item\nrescue ArgumentError => e\n  raise unless e.message == 'cannot enqueue nil'\n  logger.warn('skipped nil task')\nend","preventionTips":["Call #compact on source arrays before bulk enqueue.","Use hash.fetch with a default instead of hash[] for values going into the queue.","Items must also be mutually comparable (respond to <=>); check that alongside non-nilness."],"tags":["concurrent-ruby","priority-queue","nil","jruby","argumenterror"],"backgroundTag":"nil-value-rejected","analyzedSha":"0b88d5ff75f69b3740c8f0868e76f833cb2fd45d","analyzedAt":"2026-08-21T20:12:56.291Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}