RFR: 8346785: Potential infinite loop in JavadocTokenizer.ensures

Vicente Romero vromero at openjdk.org
Tue Apr 15 14:15:50 UTC 2025


On Mon, 14 Apr 2025 10:59:48 GMT, Nizar Benalla <nbenalla at openjdk.org> wrote:

> Please review this patch to fix a potential infinite loop in `JavadocTokenizer.ensure` when `map.length` and `size + need` approach Interger.MAX_VALUE.
> 
> While I couldn't reproduce the issue even with large inputs (~1.9GB java file where almost the entire file is one javadoc comment), the fix is about correctness and prevention of UB in extreme cases.
> 
> TIA

src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java line 309:

> 307: 
> 308:             while (need > grow && grow <= Integer.MAX_VALUE/2) {
> 309:                 grow <<= 1;

I wonder why `map` is not an `ArrayList` which already have a grow strategy. If this is because of performance issues I think that stop growing the array as soon as `grow > Integer.MAX_VALUE / 2` is a bit premature as there is still plenty of room for a less aggressive growing strategy

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/24620#discussion_r2044679939


More information about the javadoc-dev mailing list