Skip to content

Commit 584bb6a

Browse files
authored
HDDS-14955. Improve BigInteger instantiation (#10035)
1 parent a650a90 commit 584bb6a

5 files changed

Lines changed: 6 additions & 8 deletions

File tree

dev-support/pmd/pmd-ruleset.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<rule ref="category/java/performance.xml/AddEmptyString"/>
4040
<rule ref="category/java/performance.xml/AppendCharacterWithChar" />
4141
<rule ref="category/java/performance.xml/AvoidFileStream"/>
42+
<rule ref="category/java/performance.xml/BigIntegerInstantiation"/>
4243
<rule ref="category/java/performance.xml/ConsecutiveAppendsShouldReuse"/>
4344
<rule ref="category/java/performance.xml/InefficientEmptyStringCheck"/>
4445
<rule ref="category/java/performance.xml/InefficientStringBuffering"/>

hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/client/DefaultCertificateClient.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,15 @@ private void updateCachedData(
272272
}
273273

274274
private synchronized void updateCachedRootCAId(String s) {
275-
BigInteger candidateNewId = new BigInteger(s);
276275
if (rootCaCertId == null
277-
|| new BigInteger(rootCaCertId).compareTo(candidateNewId) < 0) {
276+
|| new BigInteger(rootCaCertId).compareTo(new BigInteger(s)) < 0) {
278277
rootCaCertId = s;
279278
}
280279
}
281280

282281
private synchronized void updateCachedSubCAId(String s) {
283-
BigInteger candidateNewId = new BigInteger(s);
284282
if (caCertId == null
285-
|| new BigInteger(caCertId).compareTo(candidateNewId) < 0) {
283+
|| new BigInteger(caCertId).compareTo(new BigInteger(s)) < 0) {
286284
caCertId = s;
287285
}
288286
}

hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/security/x509/certificate/utils/SelfSignedCertificate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private X509Certificate generateCertificate(BigInteger caCertSerialId) throws Op
117117

118118
BigInteger serial;
119119
if (caCertSerialId == null) {
120-
serial = new BigInteger(Long.toString(Time.monotonicNow()));
120+
serial = BigInteger.valueOf(Time.monotonicNow());
121121
} else {
122122
serial = caCertSerialId;
123123
}

hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/security/RootCARotationManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,7 @@ public void run() {
378378
CertificateServer newRootCAServer = null;
379379
BigInteger newId = BigInteger.ONE;
380380
try {
381-
newId = new BigInteger(String.valueOf(
382-
sequenceIdGen.getNextId(CERTIFICATE_ID)));
381+
newId = BigInteger.valueOf(sequenceIdGen.getNextId(CERTIFICATE_ID));
383382
newRootCAServer =
384383
HASecurityUtils.initializeRootCertificateServer(secConf,
385384
scm.getCertificateStore(), scmStorageConfig, newId,

hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/security/TestRootCARotationManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public class TestRootCARotationManager {
9292
private File testDir;
9393
private String cID = UUID.randomUUID().toString();
9494
private String scmID = UUID.randomUUID().toString();
95-
private BigInteger certID = new BigInteger("1");
95+
private BigInteger certID = BigInteger.ONE;
9696

9797
@BeforeEach
9898
public void init() throws IOException, TimeoutException,

0 commit comments

Comments
 (0)