RFR 8223174 : Pattern.compile() can throw confusing NegativeArraySizeException

Ivan Gerasimov ivan.gerasimov at oracle.com
Sat May 4 01:32:53 UTC 2019

Thank you Martin for review!

On 5/3/19 6:05 PM, Martin Buchholz wrote:
> Test should check that Pattern.compile does not return normally, e.g. 
> by throwing AssertionError.  Otherwise LGTM.
Well.  I think, that OOM in this scenario is a limitation of the current 
If the implementation of Pattern changes, so that it won't need to 
allocate that temp array, then it will not have to necessarily throw, as 
the pattern is valid.

With kind regards,

> On Fri, May 3, 2019 at 5:54 PM Ivan Gerasimov 
> <ivan.gerasimov at oracle.com <mailto:ivan.gerasimov at oracle.com>> wrote:
>     Hello!
>     A private method Pattern. RemoveQEQuoting() contains calculation
>     of an
>     array size, which can result in numeric overflow, and cause a
>     confusing
>     NegativeArraySizeException.
>     Would you please help review the fix?
>     Please note, that expressions `j + 2` and `pLen - i` cannot overflow
>     (because j is the index of a substring "\Q", and i is an index <
>     pLen),
>     so they are not wrapped with exactXXX() methods.
>     BUGURL: https://bugs.openjdk.java.net/browse/JDK-8223174
>     WEBREV: http://cr.openjdk.java.net/~igerasim/8223174/00/webrev/
>     <http://cr.openjdk.java.net/%7Eigerasim/8223174/00/webrev/>
>     -- 
>     With kind regards,
>     Ivan Gerasimov

With kind regards,
Ivan Gerasimov

More information about the core-libs-dev mailing list