rootvector2 opened a new pull request, #448: URL: https://github.com/apache/commons-beanutils/pull/448
`LazyDynaBean.growIndexedProperty` grows an indexed property to whatever index is asked for, filling every slot up to it. The index comes straight from property expressions, so `BeanUtils.populate(lazyDynaBean, request.getParameterMap())`, the usage `LazyDynaBean` is built for, lets one short parameter name decide how much memory the server allocates. `LazyDynaList.growList` does the same for `get`/`set`/`add`, reached through `PropertyUtils` indexed access on any bean property of type `LazyDynaList`. Found while reading the auto-grow paths reachable from `DefaultResolver` indexes. Reproduced with `BeanUtils.populate(new LazyDynaBean(), Map.of(key, "v"))` on `-Xmx1g`: ``` x[1000000] -> size 1000001, 136 ms, ~14 MiB retained x[50000000] -> size 50000001, 581 ms, ~807 MiB retained x[2147483646] -> OutOfMemoryError: Java heap space after 1757 ms ``` A 14-byte key exhausts the shared heap, so concurrent requests fail too. With the patch, both large keys fail fast with `IndexOutOfBoundsException`, which `get`/`set` already declare, and `x[10]` / `x[255]` behave as before. The bound limits how many elements a single access may add (default 256, the same default Spring's `DataBinder` uses for its auto-grow limit), not the total size. Filling a property one element at a time still grows without limit. Callers that legitimately jump far ahead can raise it with `setAutoGrowLimit`. The check lives in the two grow methods because every path into them (`DynaBean.get/set`, `PropertyUtils`, `BeanUtils.populate`, `List.get/set/add/addAll`) ends there. `LazyDynaMap` inherits the `LazyDynaBean` change. `LazyDynaBeanTest.testIndexedAutoGrowLimit` and `LazyDynaListTest.testAutoGrowLimit` cover lists, arrays, the `populate` path and raising the limit. The behavioral assertions fail on master: `set(name, 100000, v)` grows instead of throwing, and `set(name, Integer.MAX_VALUE, v)` on a `String[]` property throws `NegativeArraySizeException`. Default `mvn` is green (1319 tests, rat, checkstyle, japicmp, javadoc). Before you push a pull request, review this list: - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project. - [x] Read the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) if you use Artificial Intelligence (AI). - [ ] I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute? - [x] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself. - [x] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice. - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. - [x] Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
