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

PAYARA-3913 SonarQube - Instantiating wrappers - from 'new Wrapper(arg)' to 'Wrapper.valueOf(arg)' #4033

Merged
merged 2 commits into from
Jun 11, 2019
Merged

PAYARA-3913 SonarQube - Instantiating wrappers - from 'new Wrapper(arg)' to 'Wrapper.valueOf(arg)' #4033

merged 2 commits into from
Jun 11, 2019

Conversation

dvmarcilio
Copy link
Contributor

This PR fixes multiple SonarQube violations of the rule: Constructors should not be used to instantiate "String", "BigInteger", "BigDecimal" and primitive-wrapper classes

The rule says:

Constructors for String, BigInteger, BigDecimal and the objects used to wrap primitives should never be used. Doing so is less clear and uses more memory than simply using the desired value in the case of strings, and using valueOf for everything else.

Copy link
Contributor

@jbee jbee left a comment

Choose a reason for hiding this comment

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

Thanks @dvmarcilio , much appreciated. I think for the primitives in array initialisers you can drop the wrapper altogether and let the compiler do that, e.g. Object[] foo = { 1, 2 } works just fine.

@jbee
Copy link
Contributor

jbee commented Jun 11, 2019

jenkins test please

@jbee jbee added PR: CLA CLA submitted on PR by the contributor community-contribution labels Jun 11, 2019
@dvmarcilio
Copy link
Contributor Author

Thanks @dvmarcilio , much appreciated. I think for the primitives in array initialisers you can drop the wrapper altogether and let the compiler do that, e.g. Object[] foo = { 1, 2 } works just fine.

Good point! I think I covered all the cases for this situation. While I was at it, I took the liberty to add blank spaces between the arguments.

@jbee
Copy link
Contributor

jbee commented Jun 11, 2019

jenkins test please

@jbee jbee merged commit f563fc2 into payara:master Jun 11, 2019
@Pandrex247 Pandrex247 changed the title SonarQube - Instantiating wrappers - from 'new Wrapper(arg)' to 'Wrapper.valueOf(arg)' PAYARA-3913 SonarQube - Instantiating wrappers - from 'new Wrapper(arg)' to 'Wrapper.valueOf(arg)' Jun 12, 2019
@arjantijms arjantijms added this to the 5.193 milestone Jul 5, 2019
AlanRoth pushed a commit to AlanRoth/Payara that referenced this pull request Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: CLA CLA submitted on PR by the contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants