Skip to content

suppress class and declaringClass pseudo-properties in BeanMap#412

Open
rootvector2 wants to merge 1 commit into
apache:masterfrom
rootvector2:beanmap-suppress-class
Open

suppress class and declaringClass pseudo-properties in BeanMap#412
rootvector2 wants to merge 1 commit into
apache:masterfrom
rootvector2:beanmap-suppress-class

Conversation

@rootvector2

Copy link
Copy Markdown
Contributor

BeanMap.initialize introspects the bean with java.beans.Introspector directly and registers every property descriptor, so the class pseudo-property (Object.getClass, present on every bean) and declaringClass (Enum.getDeclaringClass, on enums) become map entries. PropertyUtilsBean registers SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS/SUPPRESS_DECLARING_CLASS by default to drop exactly these, but BeanMap applies no suppression, so new BeanMap(bean).get("class") hands back the bean's Class and its class loader, and keySet()/entrySet() enumerate that entry to any caller treating the BeanMap as an opaque Map. Skip both names in initialize(), matching the "class".equals(name) guard already in BeanUtilsBean.copyProperties.

Found while auditing which introspection paths honor the default class suppression; BeanMap was the one that reintroduces it. BeanMapTest.testClassPropertyNotExposed fails without the runtime change. Updated the sample key/value arrays that pinned the class entry.

  • 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.

BeanMap.initialize introspected the bean directly and registered the
class/declaringClass pseudo-properties, so BeanMap.get("class") returned
the bean's class loader that PropertyUtilsBean suppresses by default. Skip
both names during initialization.
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