4444import java .io .File ;
4545import java .io .IOException ;
4646import java .io .InputStream ;
47+ import java .lang .reflect .Method ;
4748import java .security .CodeSigner ;
4849import java .security .KeyStore ;
4950import java .security .Timestamp ;
6465import java .util .regex .Pattern ;
6566import java .util .zip .ZipException ;
6667
68+ import static java .lang .Boolean .TRUE ;
6769import static java .time .temporal .ChronoUnit .MONTHS ;
6870
6971/**
@@ -609,7 +611,7 @@ private void checkCertUsage(final CertPath certPath, final X509Certificate userC
609611
610612 final NetscapeCertTypeExtension extn = new NetscapeCertTypeExtension (encoded );
611613
612- if (!extn . get ( NetscapeCertTypeExtension . OBJECT_SIGNING )) {
614+ if (!hasObjectSigningExtension ( extn )) {
613615 certs .get (certPath ).setBadNetscapeCertType ();
614616 }
615617 }
@@ -618,6 +620,18 @@ private void checkCertUsage(final CertPath certPath, final X509Certificate userC
618620 }
619621 }
620622
623+ private static boolean hasObjectSigningExtension (NetscapeCertTypeExtension extn ) throws IOException {
624+ // method return type of "NetscapeCertTypeExtension.get()" has changed from Boolean to boolean with Java 21
625+ try {
626+ final Method getMethod = NetscapeCertTypeExtension .class .getDeclaredMethod ("get" , String .class );
627+ final Object result = getMethod .invoke (extn , NetscapeCertTypeExtension .OBJECT_SIGNING );
628+ return result == TRUE ;
629+ } catch (Exception e ) {
630+ LOG .error ("Failed to get object_signing from extension" , e );
631+ return false ;
632+ }
633+ }
634+
621635 /**
622636 * Returns if all jars are signed.
623637 *
0 commit comments