JDK-8233016 : Specify the exceptions that can be thrown by the javax.crypto.Cipher constructor
  • Type: Bug
  • Component: security-libs
  • Sub-Component: javax.crypto
  • Affected Version: 14
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-10-25
  • Updated: 2019-12-13
  • Resolved: 2019-12-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 14
14 b27Fixed
Related Reports
CSR :  
Sub Tasks
JDK-8234609 :  
Description
When using a protected constructor 
javax.crypto.Cipher���(CipherSpi, Provider, String)
and running a standalone sample implementation an NPE could be thrown which is not specified anyhow.

Exception in thread "main" java.lang.NullPointerException
	at java.base/javax.crypto.Cipher.<init>(Cipher.java:279)
	at TestCipherSpi$MyCipher.<init>(TestCipherSpi.java:23)
	at TestCipherSpi.main(TestCipherSpi.java:28)

===================
....
    static class MyCipher extends Cipher {
        protected MyCipher(javax.crypto.CipherSpi cipherSpi, Provider provider, String transformation) {
            super(cipherSpi, provider, transformation);
        }
    }
    
    public static void main(String[] args) throws Exception {
        Cipher cipher = new MyCipher(mockedCipherSpi, new Provider("a", "b", "c") {
            @Override
            public Provider configure(String configArg) {
                return super.configure(configArg);
            }
        }, "abc");        
    }
    
    static CipherSpi mockedCipherSpi = new CipherSpi() {
   ...
===================


Please see the attached full code sample to reproduce the problem.


Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/832efc785f53 User: valeriep Date: 2019-12-05 03:57:00 +0000
05-12-2019

It seems IAE is probably the best fit. Will go with IAE unless a better solution is found.
13-11-2019

NPE is a weird exception to throw for this case because it is not because the provider parameter is null. I'd be more inclined to change it to throw IllegalArgumentException or InvalidParameterException.
01-11-2019