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

TRUE/FALSE_RETURNS at odds with NAB_NEEDLESS_BOOLEAN_CONSTANT_CONVERSION from fb-contrib #957

Closed
davidburstrom opened this issue Nov 6, 2021 · 6 comments

Comments

@davidburstrom
Copy link
Contributor

With Pitest 1.7.2:

Given

Boolean getValue() {
  return Boolean.TRUE;
}

the TRUE_RETURNS mutator will produce the mutation

Boolean getValue() {
  return true;
}

which will always survive as the true will be auto-boxed to a Boolean instance (unless we're testing Boolean instance identity, which seems pointless). The problem is that changing the production code to match the mutation is at odds with the NAB_NEEDLESS_BOOLEAN_CONSTANT_CONVERSION bug type from fb-contrib (See http://fb-contrib.sourceforge.net/bugdescriptions.html).

I might be missing some edge case here, but I think that the TRUE_RETURNS mutator shouldn't try to return true in lieu of Boolean.TRUE, due to the auto-boxing. I'd be happy to understand if it is indeed a relevant case.

The corresponding argument can be made for FALSE_RETURNS, of course.

@hcoles
Copy link
Owner

hcoles commented Nov 6, 2021

It is highly unlikely that the autoboxing in return true will have any measurable impact on performance/object allocation etc, so personally I would always use this more readable version, and not enable static analysis rules such as this.

Having said that, codebases and opinions differ, and there may be scenarios where the boxing does make a difference.

I'll take a look out at filtering mutatants of this form in the next release.

@davidburstrom
Copy link
Contributor Author

@mebigfatguy My apologies for roping you into this, but maybe you have some input on the performance benefits of the linter in question?

hcoles added a commit that referenced this issue Nov 8, 2021
Filter mutants returning Boolean.TRUE & Bollean.FALSE for #957
@hcoles
Copy link
Owner

hcoles commented Nov 9, 2021

Released in 1.7.3

@hcoles hcoles closed this as completed Nov 9, 2021
@davidburstrom
Copy link
Contributor Author

Thank you very much for addressing it so fast :)

@hcoles
Copy link
Owner

hcoles commented Nov 9, 2021

This repo has 2 response times: 3 years or 3 days.

@davidburstrom
Copy link
Contributor Author

I think you decreased the average response time with this one :)

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