GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] BooleanGetMethodName should have the option to treat boolean wrapper type differently · Issue #6958 · pmd/pmd

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

New issue
Copy link
New issue
Copy link
Closed
Closed
[java] BooleanGetMethodName should have the option to treat boolean wrapper type differently#6958
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
7.27.0

Description

@harbulot
harbulot
opened on Aug 7, 2026
Issue body actions

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. harbulot
    added
    a:false-positivePMD flags a piece of code that is not problematic
    on Aug 7, 2026
  2. harbulot
    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. UncleOwen
    added this to the 7.27.0 milestone on Aug 10, 2026
  4. UncleOwen
    closed this as completedon 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-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.27.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.