Attila Doroszlai created HDDS-14955:
---------------------------------------
Summary: Improve BigInteger instantiation
Key: HDDS-14955
URL: https://issues.apache.org/jira/browse/HDDS-14955
Project: Apache Ozone
Issue Type: Improvement
Reporter: Attila Doroszlai
Assignee: Rishabh Patel
0. Enable
[BigIntegerInstantiation|https://docs.pmd-code.org/latest/pmd_rules_java_performance.html#bigintegerinstantiation]
PMD rule to avoid creating instances of already existing BigInteger.
1. Avoid unnecessary String conversion. {{new
BigInteger(String.valueOf(<long>))}} (or {{Long.toString}}) should be changed
to {{BigInteger.valueOf(<long>)}}:
https://github.com/apache/ozone/blob/644a018e63a42225307036375c7cf2e7c1178917/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/utils/SelfSignedCertificate.java#L120
https://github.com/apache/ozone/blob/644a018e63a42225307036375c7cf2e7c1178917/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/security/RootCARotationManager.java#L381-L382
{code}
jshell> var t = System.currentTimeMillis()
t ==> 1775031247575
jshell> var o = new BigInteger(String.valueOf(t))
o ==> 1775031247575
jshell> var n = BigInteger.valueOf(t)
n ==> 1775031247575
jshell> o.equals(n)
$4 ==> true
{code}
2. Avoid eager instantiation.
https://github.com/apache/ozone/blob/644a018e63a42225307036375c7cf2e7c1178917/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/client/DefaultCertificateClient.java#L274-L288
{{candidateNewId}} variable can be inlined.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]