{"record":{"id":"0e7b49af46868fc1","repo":"ruby-concurrency/concurrent-ruby","slug":"value-is-less-than-the-maximum-value-of-min-v","errorCode":null,"errorMessage":"#{value} is less than the maximum value of #{MIN_VALUE}","messagePattern":"#(.+?) is less than the maximum value of #(.+?)","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"lib/concurrent-ruby/concurrent/utility/native_integer.rb","lineNumber":19,"sourceCode":"module Concurrent\n  # @!visibility private\n  module Utility\n    # @private\n    module NativeInteger\n      # http://stackoverflow.com/questions/535721/ruby-max-integer\n      MIN_VALUE = -(2**(0.size * 8 - 2))\n      MAX_VALUE = (2**(0.size * 8 - 2) - 1)\n\n      def ensure_upper_bound(value)\n        if value > MAX_VALUE\n          raise RangeError.new(\"#{value} is greater than the maximum value of #{MAX_VALUE}\")\n        end\n        value\n      end\n\n      def ensure_lower_bound(value)\n        if value < MIN_VALUE\n          raise RangeError.new(\"#{value} is less than the maximum value of #{MIN_VALUE}\")\n        end\n        value\n      end\n\n      def ensure_integer(value)\n        unless value.is_a?(Integer)\n          raise ArgumentError.new(\"#{value} is not an Integer\")\n        end\n        value\n      end\n\n      def ensure_integer_and_bounds(value)\n        ensure_integer value\n        ensure_upper_bound value\n        ensure_lower_bound value\n      end\n\n      def ensure_positive(value)","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/ruby-concurrency/concurrent-ruby/blob/0b88d5ff75f69b3740c8f0868e76f833cb2fd45d/lib/concurrent-ruby/concurrent/utility/native_integer.rb#L1-L37","documentation":"The lower-bound twin of the maximum check: values below -(2**62) cannot be held in a native fixnum slot, so storing them into AtomicFixnum (new, value=, update) or the count-taking constructors of Semaphore/CountDownLatch/CyclicBarrier raises RangeError. Ruby's arbitrary-precision arithmetic happily produces such values right up to the store.","triggerScenarios":"Concurrent::AtomicFixnum.new(-(2**62)); counter.update { |v| v - 2**62 } from a subtraction of big aggregates; negating a large positive counter; semaphore/latch counts computed as differences of big numbers.","commonSituations":"Balance/credit arithmetic going deeply negative before a domain check runs; mirroring large external counters (negative deltas); JRuby-to-MRI porting where the native range differs.","solutions":["Validate before storing: raise RangeError, 'below native minimum' if value < Concurrent::Utility::NativeInteger::MIN_VALUE","Clamp when undershoot has a defined floor: value = [value, Concurrent::Utility::NativeInteger::MIN_VALUE].max","Move unbounded arithmetic into plain Integers + Mutex, using AtomicFixnum only where values provably stay in range"],"exampleFix":"# before\nbalance = Concurrent::AtomicFixnum.new(-(2**62) - 1) # RangeError\n\n# after\nmin = Concurrent::Utility::NativeInteger::MIN_VALUE\nraise RangeError, 'balance underflow' if amount < min\nbalance = Concurrent::AtomicFixnum.new(amount)","handlingStrategy":"validation","validationCode":"NI = Concurrent::Utility::NativeInteger\nraise RangeError, \"#{value} below atomic counter range\" if value.is_a?(Integer) && value < NI::MIN_VALUE\nConcurrent::AtomicFixnum.new(value)","typeGuard":"def native_int?(v)\n  v.is_a?(Integer) &&\n    v.between?(Concurrent::Utility::NativeInteger::MIN_VALUE,\n               Concurrent::Utility::NativeInteger::MAX_VALUE)\nend","tryCatchPattern":"begin\n  counter.value = next_value\nrescue RangeError\n  counter.value = Concurrent::Utility::NativeInteger::MIN_VALUE # explicit floor + alert\nend","preventionTips":["Check the MIN_VALUE bound before storing negated or deeply negative values","Run domain floor checks (e.g. balance >= 0) before arithmetic reaches the atomic","Alert on saturation instead of letting it pass silently"],"tags":["ruby","concurrency","atomic","range-error","integer-underflow"],"backgroundTag":"integer-underflow","analyzedSha":"0b88d5ff75f69b3740c8f0868e76f833cb2fd45d","analyzedAt":"2026-08-21T20:12:56.291Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}