Skip to content

bound auto-grow of indexed properties in LazyDynaBean and LazyDynaList - #448

Open
rootvector2 wants to merge 1 commit into
apache:masterfrom
rootvector2:lazy-dyna-autogrow-limit
Open

rootvector2 wants to merge 1 commit into
apache:masterfrom
rootvector2:lazy-dyna-autogrow-limit

Conversation

@rootvector2

Copy link
Copy Markdown
Contributor

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:

  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance 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?
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • 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.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • 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.

growIndexedProperty and growList filled an indexed property up to any
requested index. the index comes from property expressions, so a single
populate key like x[2147483646] made a LazyDynaBean append ~2^31
elements until the heap ran out.

limit how many elements one access may add (default 256, configurable
with setAutoGrowLimit) and throw IndexOutOfBoundsException past it.
appending one element at a time is unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant