Skip to content

fix: replace deprecated X509Certificate.getSubjectDN() and getIssuerDN() with X500Principal equivalents#3283

Open
itsmohitnarayan wants to merge 1 commit intoAutoMQ:mainfrom
itsmohitnarayan:fix/replace-deprecated-x509-methods
Open

fix: replace deprecated X509Certificate.getSubjectDN() and getIssuerDN() with X500Principal equivalents#3283
itsmohitnarayan wants to merge 1 commit intoAutoMQ:mainfrom
itsmohitnarayan:fix/replace-deprecated-x509-methods

Conversation

@itsmohitnarayan
Copy link
Copy Markdown
Contributor

Summary

Replace deprecated X509Certificate.getSubjectDN() and X509Certificate.getIssuerDN() methods with their recommended X500Principal equivalents in CommonNameLoggingTrustManagerFactoryWrapper.java.

Changes

  • getSubjectDN()getSubjectX500Principal()
  • getIssuerDN()getIssuerX500Principal()
  • Removed unused java.security.Principal import

Why

Per JDK-4959744, both methods have been deprecated since JDK 16 because:

  • The old methods returned Principal with implementation-dependent getName() output
  • X500Principal provides well-defined RFC 2253 output, making the behavior consistent across JVMs

This eliminates the deprecation warnings reported in #3282:

CommonNameLoggingTrustManagerFactoryWrapper.java:374: warning: [deprecation] getSubjectDN() in X509Certificate has been deprecated
CommonNameLoggingTrustManagerFactoryWrapper.java:375: warning: [deprecation] getSubjectDN() in X509Certificate has been deprecated
CommonNameLoggingTrustManagerFactoryWrapper.java:324: warning: [deprecation] getIssuerDN() in X509Certificate has been deprecated
CommonNameLoggingTrustManagerFactoryWrapper.java:325: warning: [deprecation] getIssuerDN() in X509Certificate has been deprecated

Testing

  • The return type change from PrincipalX500Principal is binary compatible since X500Principal implements Principal
  • Existing tests should pass as X500Principal.getName() returns the same DN format

Fixes #3282

@itsmohitnarayan itsmohitnarayan marked this pull request as draft April 3, 2026 07:56
@itsmohitnarayan itsmohitnarayan force-pushed the fix/replace-deprecated-x509-methods branch from 55efd62 to ce083ec Compare April 3, 2026 08:13
Replace deprecated methods with their X500Principal equivalents:
- getSubjectDN() → getSubjectX500Principal()
- getIssuerDN() → getIssuerX500Principal()

Both deprecated methods have implementation-dependent behavior, while
X500Principal provides well-defined RFC 2253 output via getName().

Added @SuppressWarnings for overriding deprecated abstract methods
with clarifying comments explaining the necessity.

Updated test assertions to use X500Principal for proper comparison.

Fixes AutoMQ#3282
@itsmohitnarayan itsmohitnarayan force-pushed the fix/replace-deprecated-x509-methods branch from ce083ec to 1219140 Compare April 3, 2026 08:25
@itsmohitnarayan itsmohitnarayan marked this pull request as ready for review April 3, 2026 09:01
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

Successfully merging this pull request may close these issues.

[CLEANUP] Replace deprecated X509Certificate.getSubjectDN() and getIssuerDN() with X500Principal equivalents

1 participant