RFR: 8365288: PEMDecoder should throw ClassCastException

Chen Liang liach at openjdk.org
Tue Aug 12 14:46:12 UTC 2025


On Tue, 12 Aug 2025 11:49:50 GMT, Weijun Wang <weijun at openjdk.org> wrote:

>> 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())`
>
> I cannot say the name is confusing because I actually don't know what it means. Over the years I've learnt to read it as `isParentOf`.

I think it refers to the concept of

Exception ex = new ClassCastException();

So `Exception.class.isAssignableFrom(ClassCastException.class)` is true.

I agree this name is confusing indeed.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/26734#discussion_r2270116663


More information about the security-dev mailing list