Hi Mark: please help review: [perf] Check for EOF before the numeric test in readHostIPv4 by leeychee · Pull Request #1068 · apache/tomcat <https://github.com/apache/tomcat/pull/1068>
Best regards Chunhui Liu Mark Thomas <[email protected]> 于2026年9月17日周四 18:18写道: > On 17/09/2026 10:53, Chunhui Liu wrote: > > Hi team: > > > > Recently, we noticed that there are hundreds > > of ArrayIndexOutOfBoundsExceptions (and deoptimization events) have been > > thrown by `HttpParser.readHostIPv4`. It can be reproduced with the > > following test case: > > > > ```java > > > > @Test > > void debugStandardIpv4_isNumericOnEof() throws IOException { > > HttpParser.readHostIPv4(new StringReader("127.0.0.1"), false); > > } > > > > ``` > > > > The method does not throws the exception directly, but rather swallows it > > inside `isNumeric` through the following steps: > > > > > > 1. All characters are read, reaching EOF and returning -1; > > 2. The `isNumeric` check is performed before the `-1` check; > > 3. `-1` triggers an ArrayIndexOutOfBoundsException inside isNumeric; > > > > [image: image.png] > > [image: image.png] > > > > So my question is: > > > > 1. Should the `-1` branch be placed before the `isNumeric` branch? or is > > there another reason for the current implementation? > > 2. Should check `0 < c < ARRAY_SIZE`? > > Option 1 is the better choice. > > Not option 2 since those methods are deliberately designed to be as fast > as possible for valid input. > > PRs welcome. > > Mark > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
