Copilot commented on code in PR #15743:
URL: https://github.com/apache/dubbo/pull/15743#discussion_r2488459781
##########
dubbo-plugin/dubbo-security/src/main/java/org/apache/dubbo/security/cert/DubboCertManager.java:
##########
@@ -368,10 +368,9 @@ private String generatePrivatePemKey(KeyPair keyPair)
throws IOException {
private String generatePemKey(String type, byte[] content) throws
IOException {
PemObject pemObject = new PemObject(type, content);
StringWriter str = new StringWriter();
- JcaPEMWriter jcaPEMWriter = new JcaPEMWriter(str);
- jcaPEMWriter.writeObject(pemObject);
- jcaPEMWriter.close();
- str.close();
+ try (JcaPEMWriter jcaPEMWriter = new JcaPEMWriter(str)) {
+ jcaPEMWriter.writeObject(pemObject);
+ }
return str.toString();
Review Comment:
The StringWriter should be included in the try-with-resources statement to
ensure it is properly closed. While StringWriter.close() doesn't throw
exceptions or manage external resources, following the pattern consistently
ensures best practices.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]