RFR: 8298420: PEM API: Implementation (Preview) [v12]

Sean Mullan mullan at openjdk.org
Mon May 5 15:31:57 UTC 2025


On Thu, 17 Apr 2025 21:39:31 GMT, Anthony Scarpino <ascarpino at openjdk.org> wrote:

>> src/java.base/share/classes/java/security/PEMDecoder.java line 377:
>> 
>>> 375:      * {@code provider} will occur during decoding.
>>> 376:      *
>>> 377:      * <p>If {@code params} is {@code null}, a new instance is returned with
>> 
>> There is no variable named `params` - do you mean `provider`? Also, why not throw an NPE and not allow a `null` provider, since it would be the same as calling `of()`?
>
> It was meant to be `provider`.
> I didn't think checking for null and throwing an exception is necessary when it is the default operation.   This shows up when coding with a provider variable with unknown value.  In this case, the app doesn't have to check if `provider == null` so that it can call `of()`.  Unfortunately this situation is common with `getInstance()` which result in a lot of if-else statements.

I think that case is arguably an issue that the caller should know about, by throwing an exception. If the caller has some code where it thinks it is trying to use a provider, and the API is not doing what the caller thinks it should, then I think this API here should throw an exception. The caller can easily work around this, by calling `of()` when provider is null.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17543#discussion_r2073671278


More information about the security-dev mailing list