{"record":{"id":"fbc5d34ef5226835","repo":"ruby-concurrency/concurrent-ruby","slug":"cannot-enqueue-nil-fbc5d3","errorCode":null,"errorMessage":"cannot enqueue nil","messagePattern":"cannot enqueue nil","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/concurrent-ruby/concurrent/collection/ruby_non_concurrent_priority_queue.rb","lineNumber":79,"sourceCode":"        empty? ? nil : @queue[1]\n      end\n\n      # @!macro priority_queue_method_pop\n      def pop\n        return nil if empty?\n        max = @queue[1]\n        swap(1, @length)\n        @length -= 1\n        sink(1)\n        @queue.pop\n        max\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        @length += 1\n        @queue << item\n        swim(@length)\n        true\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\n      private\n\n      # Exchange the values at the given indexes within the internal array.","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/ruby-concurrency/concurrent-ruby/blob/0b88d5ff75f69b3740c8f0868e76f833cb2fd45d/lib/concurrent-ruby/concurrent/collection/ruby_non_concurrent_priority_queue.rb#L61-L97","documentation":"This is the pure-Ruby heap engine used by Concurrent::PriorityQueue on non-JRuby platforms. As with the Java variant, nil is the queue's 'empty' sentinel (pop returns nil when the heap is exhausted), so push rejects nil items with ArgumentError to keep a stored nil distinguishable from an empty queue.","triggerScenarios":"`queue.push(nil)`, `queue << nil`, `queue.enq(nil)`; `queue << record[:deadline]` where the field is absent; from_list over an array containing nils.","commonSituations":"Optional or missing values from config, APIs, or database rows flowing into a scheduling queue; nil used as a placeholder for 'not yet computed'; skipping #compact on bulk input.","solutions":["Skip or filter nils before enqueueing: `items.compact.each { |i| queue << i }`.","Substitute a real default via fetch for values destined for the queue.","Use a null-object sentinel (with <=> defined) or a wrapper Struct when 'absent' must be queued.","Remember items must be mutually comparable anyway — validate comparability along with non-nilness."],"exampleFix":"// before\nitems.each { |i| queue << i }   # i is nil for missing entries -> ArgumentError\n\n// after\nitems.compact.each { |i| queue << i }","handlingStrategy":"validation","validationCode":"items.compact.each { |i| queue << i }","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 item')\nend","preventionTips":["Filter nils at ingestion, not at enqueue time under load.","Use fetch(key, default) or a null-object sentinel for absent values.","Validate comparability of queued items once at the boundary, since the heap requires <=>."],"tags":["concurrent-ruby","priority-queue","nil","argumenterror"],"backgroundTag":"nil-value-rejected","analyzedSha":"0b88d5ff75f69b3740c8f0868e76f833cb2fd45d","analyzedAt":"2026-08-21T20:12:56.291Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}