Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7188
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Using Enumerated Types as Array Indexes |
| Date | 2011-08-17 21:34 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <j2hq8t$mcm$1@dont-email.me> (permalink) |
| References | (5 earlier) <6d418cda-dab3-43df-a9ec-293b43f2bbd8@glegroupsg2000goo.googlegroups.com> <vTL2q.38278$tp.27319@newsfe06.iad> <slrnj4ngfi.6gl.avl@gamma.logic.tuwien.ac.at> <f08d98e8-e04d-4d4e-b518-44bba735dba6@glegroupsg2000goo.googlegroups.com> <9b2aglFuj7U1@mid.individual.net> |
On 8/17/2011 1:02 PM, Robert Klemme wrote:
> On 17.08.2011 16:17, Lew wrote:
>> Andreas Leitgeb wrote:
>>> Arved Sandstrom<asandstr...@eastlink.ca> wrote:
>>>> Lew wrote:
>>>>> JLS 10: [...] IOW, you never index arrays with a byte, char or
>>>>> short. [...]
>>>> I'm feeling slow this morning: how do we get problems with
>>>> byte->int, short->int, or char->int again?
>>
>> One gets problems with byte->int and short->int with array indexes
>> the way one gets into trouble with those widening conversions
>> generally. The usual suspect is the lack of unsigned versions, so
>> widening a (byte)0xA0, for example, would result in a negative
>> index.
>>
>> One gets into trouble generally in programming when one thinks one
>> thing is going on ("index takes a byte") whilst ignoring what's
>> really going on (there's a widening conversion involved). You might
>> get away with it most of the time, but occasionally such things trip
>> you up.
>
> Why had a nice issue recently which exactly fits this bill: after over
> two months of uninterrupted, completely error free production usage the
> application suddenly stopped working giving weird error messages (there
> was an issue with the error reporting as well, but let's ignore that for
> the moment). Turns out this was the setup:
>
> 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()).
>
> 2. The result was used to index into an array with the quite obvious
> "arr[n % arr.length]".
>
> 3. (left as exercise for the reader)
>
> Anybody who now thinks all is fine should stop coding Java immediately
> and go reading the language spec.
Yes, but what has this error to do with widening conversions,
or conversions of any kind? It's GIGO, pure and simple.
--
Eric Sosman
esosman@ieee-dot-org.invalid
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Using Enumerated Types as Array Indexes KevinSimonson <kvnsmnsn@hotmail.com> - 2011-08-16 07:53 -0700
Re: Using Enumerated Types as Array Indexes Patricia Shanahan <pats@acm.org> - 2011-08-16 09:30 -0700
Re: Using Enumerated Types as Array Indexes Tom Anderson <twic@urchin.earth.li> - 2011-08-16 21:37 +0100
Re: Using Enumerated Types as Array Indexes Gene Wirchenko <genew@ocis.net> - 2011-08-16 14:54 -0700
Re: Using Enumerated Types as Array Indexes Arne Vajhøj <arne@vajhoej.dk> - 2011-08-16 20:47 -0400
Re: Using Enumerated Types as Array Indexes Arne Vajhøj <arne@vajhoej.dk> - 2011-08-16 20:38 -0400
Re: Using Enumerated Types as Array Indexes markspace <-@.> - 2011-08-16 17:52 -0700
Re: Using Enumerated Types as Array Indexes Arne Vajhøj <arne@vajhoej.dk> - 2011-08-16 21:56 -0400
Re: Using Enumerated Types as Array Indexes markspace <-@.> - 2011-08-16 20:20 -0700
Re: Using Enumerated Types as Array Indexes Lew <lewbloch@gmail.com> - 2011-08-16 20:45 -0700
Re: Using Enumerated Types as Array Indexes Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-08-17 06:31 -0300
Re: Using Enumerated Types as Array Indexes Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-17 13:28 +0000
Re: Using Enumerated Types as Array Indexes Lew <lewbloch@gmail.com> - 2011-08-17 07:17 -0700
Re: Using Enumerated Types as Array Indexes Robert Klemme <shortcutter@googlemail.com> - 2011-08-17 19:02 +0200
Re: Using Enumerated Types as Array Indexes markspace <-@.> - 2011-08-17 16:09 -0700
Re: Using Enumerated Types as Array Indexes Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-17 23:48 +0000
Re: Using Enumerated Types as Array Indexes markspace <-@.> - 2011-08-17 17:34 -0700
Re: Using Enumerated Types as Array Indexes Patricia Shanahan <pats@acm.org> - 2011-08-17 18:07 -0700
Re: Using Enumerated Types as Array Indexes markspace <-@.> - 2011-08-18 08:22 -0700
Re: Using Enumerated Types as Array Indexes Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-18 18:37 +0000
Re: Using Enumerated Types as Array Indexes markspace <-@.> - 2011-08-18 11:50 -0700
Re: Using Enumerated Types as Array Indexes Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-18 20:49 +0000
Re: Using Enumerated Types as Array Indexes markspace <-@.> - 2011-08-18 14:48 -0700
Re: Using Enumerated Types as Array Indexes Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-18 22:50 +0000
Re: Using Enumerated Types as Array Indexes Arne Vajhøj <arne@vajhoej.dk> - 2011-08-17 21:49 -0400
Re: Using Enumerated Types as Array Indexes Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-17 21:50 -0400
Re: Using Enumerated Types as Array Indexes Robert Klemme <shortcutter@googlemail.com> - 2011-08-19 14:13 +0200
Re: Using Enumerated Types as Array Indexes Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-19 20:05 +0000
Re: Using Enumerated Types as Array Indexes Robert Klemme <shortcutter@googlemail.com> - 2011-08-20 00:20 +0200
Re: Using Enumerated Types as Array Indexes Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-19 23:11 +0000
Re: Using Enumerated Types as Array Indexes Robert Klemme <shortcutter@googlemail.com> - 2011-08-20 11:21 +0200
Re: Using Enumerated Types as Array Indexes Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-20 11:45 +0000
Re: Using Enumerated Types as Array Indexes Robert Klemme <shortcutter@googlemail.com> - 2011-08-20 15:23 +0200
Re: Using Enumerated Types as Array Indexes Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-20 16:15 +0000
Re: Using Enumerated Types as Array Indexes Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-17 21:34 -0400
Re: Using Enumerated Types as Array Indexes Robert Klemme <shortcutter@googlemail.com> - 2011-08-18 07:58 +0200
Re: Using Enumerated Types as Array Indexes Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-08-18 06:29 -0300
Re: Using Enumerated Types as Array Indexes RedGrittyBrick <RedGrittyBrick@spamweary.invalid> - 2011-08-18 10:47 +0100
Re: Using Enumerated Types as Array Indexes Lew <lewbloch@gmail.com> - 2011-08-18 11:35 -0700
Re: Using Enumerated Types as Array Indexes Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-08-18 18:30 -0300
Re: Using Enumerated Types as Array Indexes Robert Klemme <shortcutter@googlemail.com> - 2011-08-19 14:57 +0200
Re: Using Enumerated Types as Array Indexes Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-19 20:10 +0000
Re: Using Enumerated Types as Array Indexes Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-08-19 19:12 -0300
Re: Using Enumerated Types as Array Indexes Robert Klemme <shortcutter@googlemail.com> - 2011-08-20 00:26 +0200
Re: Using Enumerated Types as Array Indexes Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-19 22:59 +0000
Re: Using Enumerated Types as Array Indexes Arne Vajhøj <arne@vajhoej.dk> - 2011-08-17 21:34 -0400
Re: Using Enumerated Types as Array Indexes Arne Vajhøj <arne@vajhoej.dk> - 2011-08-17 21:46 -0400
Re: Using Enumerated Types as Array Indexes markspace <-@.> - 2011-08-17 19:51 -0700
Re: Using Enumerated Types as Array Indexes David Lamb <dalamb@cs.queensu.ca> - 2011-08-17 08:29 -0400
Re: Using Enumerated Types as Array Indexes Robert Klemme <shortcutter@googlemail.com> - 2011-08-17 16:04 +0200
Re: Using Enumerated Types as Array Indexes Arne Vajhøj <arne@vajhoej.dk> - 2011-08-17 21:51 -0400
Re: Using Enumerated Types as Array Indexes Niklas Holsti <niklas.holsti@tidorum.invalid> - 2011-08-17 11:24 +0300
Re: Using Enumerated Types as Array Indexes Arne Vajhøj <arne@vajhoej.dk> - 2011-08-17 21:55 -0400
Re: Using Enumerated Types as Array Indexes Niklas Holsti <niklas.holsti@tidorum.invalid> - 2011-08-18 10:59 +0300
Re: Using Enumerated Types as Array Indexes Roedy Green <see_website@mindprod.com.invalid> - 2011-08-17 22:09 -0700
csiph-web