Skip to content

Suppress class and declaringClass pseudo-properties in BeanMap#412

Merged
garydgregory merged 2 commits into
apache:masterfrom
rootvector2:beanmap-suppress-class
Jul 11, 2026
Merged

Suppress class and declaringClass pseudo-properties in BeanMap#412
garydgregory merged 2 commits 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.
@garydgregory garydgregory changed the title suppress class and declaringClass pseudo-properties in BeanMap Suppress class and declaringClass pseudo-properties in BeanMap Jul 11, 2026

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rootvector2
Please my see my comments.

public Object[] getSampleValues() {
final Object[] values = { Integer.valueOf(1234), Long.valueOf(1298341928234L), Double.valueOf(123423.34), Float.valueOf(1213332.12f),
Short.valueOf((short) 134), Byte.valueOf((byte) 10), Character.valueOf('a'), Integer.valueOf(1432), "SomeStringValue", objectInFullMap,
BeanWithProperties.class, };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was BeanWithProperties removed here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getSampleValues() is index-aligned with getSampleKeys() in AbstractMapTest; BeanWithProperties.class was the sample value for the class key, so removing the key means removing its value too, otherwise the arrays go out of sync.

assertNull(map.get("class"));
assertNull(map.getReadMethod("class"));

final BeanMap enumMap = new BeanMap(java.time.DayOfWeek.MONDAY);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use a fully-qualified class name here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, switched to an import of DayOfWeek.

@garydgregory garydgregory merged commit dab6123 into apache:master Jul 11, 2026
9 checks passed
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.

2 participants