Skip to content

[java] BooleanGetMethodName should have the option to treat boolean wrapper type differently #6958

Closed

Description

@harbulot

The change introduced in #5253 was made under the assumption that returning a (primitive) boolean and a (wrapped) Boolean should both be treated the same (and not use the get prefix).

Although they are similar, there are still a number of tools, including those following the Java Beans convention, that expect getFoo to be used when the wrapped Boolean type is used.

Here is an example:

import org.apache.commons.beanutils.PropertyUtils;

public class Test {
    public static class Item {
        public boolean isRed() {
            return true;
        }
        public Boolean getGreen() {
            return true;
        }
        public Boolean isBlue() {
            return true;
        }
    }

    public static void main(String[] args) throws Exception {
        Item item = new Item();

        System.out.println("Accessing isRed() -> boolean: ");
        System.out.println(PropertyUtils.getProperty(item, "red"));
        System.out.println("Accessing getGreen() -> Boolean: ");
        System.out.println(PropertyUtils.getProperty(item, "green"));
        System.out.println("Accessing isBlue() -> Boolean: ");
        System.out.println(PropertyUtils.getProperty(item, "blue"));
    }
}

Here are the results:

Accessing isRed() -> boolean: 
true
Accessing getGreen() -> Boolean: 
true
Accessing isBlue() -> Boolean: 
Exception in thread "main" java.lang.NoSuchMethodException: Unknown property 'blue' on class 'class Test$Item'
	at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1232)
	at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:783)
	at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:811)
	at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:396)
	at Test.main(Test.java:38)

This will throw an exception when trying to get the "blue" property, because isBlue() is returning a wrapped Boolean and not a primitive type.
This works for getGreen(), because it uses the "get" prefix.

When using Boolean (and not boolean), using the "get" prefix is by design in many cases.

I would suggest either to reverse #5253, or to add an option to distinguish the wrapped type case (for includeWrappedType or excludeWrappedType, depending on what the default should be).

Activity

  1. added
    a:false-positive
    on Aug 7, 2026
  2. changed the title [-]BooleanGetMethodName should have the option to treat boolean wrapper type differently[/-] [+][java] BooleanGetMethodName should have the option to treat boolean wrapper type differently[/+] on Aug 7, 2026
  3. added this to the 7.27.0 milestone on Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positive

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions