RFR: 8365288: PEMDecoder should throw ClassCastException
Chen Liang
liach at openjdk.org
Mon Aug 11 22:41:11 UTC 2025
On Mon, 11 Aug 2025 20:58:13 GMT, Anthony Scarpino <ascarpino at openjdk.org> wrote:
> This bug fix is to change PEMDecoder.decode(..., Class<>) using PKCS8EncodedKeySpec and X509EncodedKeySpec will throw an IllegalArgumentException when the decoded data does not match. It should be ClassCastException.
>
> Thanks
>
> Tony
test/jdk/java/security/PEM/PEMDecoderTest.java line 492:
> 490: testClass(entry, clazz);
> 491: } catch (Exception e) {
> 492: if (e.getClass().isAssignableFrom(ec)) {
You got it the other way around, testing if `e` is of a superclass of `ec`.
Suggestion:
if (ec.isInstance(e)) {
Or `ec.isAssignableFrom(e.getClass())`
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26734#discussion_r2268160924
More information about the security-dev
mailing list