Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean fields that start with a prefix and then "isXXX" will fail. #104

Open
francisconoriega opened this issue Aug 2, 2017 · 3 comments

Comments

@francisconoriega
Copy link

When you have a boolean field that starts with with a prefix, followed by "is", openpojo will fail to find/associate its getter.

e.g.

boolean mIsDefault; will try to find getters called getIsDefault and isIsDefault, but not isDefault

The issue is in PojoMethodFactory.generateGetMethodNames in this part

      prefix.add("is" + AttributeHelper.getAttributeName(field));
      String fieldName = field.getName();
      if (fieldName.length() > 2 && fieldName.startsWith("is") && Character.isUpperCase(fieldName.charAt(2)))
        prefix.add(fieldName);
    }

the first prefix.add will generate isIsDefault, the second prefix.add wont be executed because you are calling fieldName.startsWith instead of AttributeHelper.getAttributeName(field).startsWith.

You should also need add a toLower, making it

String attributeName = AttributeHelper.getAttributeName(field);
   if (attributeName.length() > 2 && attributeName.toLower().startsWith("is") && Character.isUpperCase(attributeName.charAt(2)))
        prefix.add(fieldName);
    }
@Yky
Copy link

Yky commented Aug 11, 2017

Works for me.

@francisconoriega
Copy link
Author

@Yky could you give an example of the field name and getter name you are using?

It should not work if you have something like mIsDefault and then a getter called isDefault

and you can see in the generated method names code above, the method names this will produce are:

prefix.add("is" + AttributeHelper.getAttributeName(field)); => isIsDefault

String fieldName = field.getName(); if (fieldName.length() > 2 && fieldName.startsWith("is") && Character.isUpperCase(fieldName.charAt(2))) prefix.add(fieldName);=> mIsDefault

so you get isIsDefault && mIsDefault but not isDefault so you wont get the right method name

francisconoriega pushed a commit to francisconoriega/openpojo that referenced this issue Aug 14, 2017
… for boolean fields that start with a prefix followed by "is".
@Yky
Copy link

Yky commented Aug 17, 2017

Why do you have the following line in your sample code.

prefix.add("is" + AttributeHelper.getAttributeName(field));

My tests work without this. The only registered prefix I have is "m".

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

No branches or pull requests

2 participants