Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Using Enumerated Types as Array Indexes Date: Wed, 17 Aug 2011 21:50:06 -0400 Organization: A noiseless patient Spider Lines: 28 Message-ID: References: <4e4b0d81$0$314$14726298@news.sunsite.dk> <4e4b1fe4$0$314$14726298@news.sunsite.dk> <6d418cda-dab3-43df-a9ec-293b43f2bbd8@glegroupsg2000goo.googlegroups.com> <9b2aglFuj7U1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 18 Aug 2011 01:51:28 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="f8igmItKsWs6nM5YanFxAA"; logging-data="27226"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XhfE7HRnHYtQGY11FsjKx" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20110624 Thunderbird/5.0 In-Reply-To: Cancel-Lock: sha1:mzqmLk98bsiJwb/0CHGx5PtMO3I= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7191 On 8/17/2011 7:09 PM, markspace wrote: > On 8/17/2011 10:02 AM, Robert Klemme wrote: > >> 1. There was an AtomicInteger initialized at startup with 0 which for >> every request coming into that system was incremented in a thread safe >> manner (incrementAndGet()). > > > I'd be shocked if an int actually overflowed when counting requests like > this, but that's all I can think of. 2^31 is such a huge number, I > didn't think you could get there in practical cases. He *did* write "two months of uninterrupted [...] usage." Two months ~= 60 days ~= 5 megaseconds, so a 2G counter overflows if it increments at ~400 Hz or more, give or take a few backs of envelopes. > Assuming that the AtomicInteger did overflow, then n % y produces > negative numbers if n is negative, a clear AIOOB. > > Try : arr[ Math.abs( n ) % arr.length ]; Bzzzzt! Thank you for playing, go back to the rear of the line. While awaiting your next opportunity, ponder: What is the sign of Math.abs(Integer.MIN_VALUE)? -- Eric Sosman esosman@ieee-dot-org.invalid