-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
7u4
-
None
-
generic
-
generic
The spec for javax.crypto.Mac.update(ByteBuffer input) method said:
"
Processes input.remaining() bytes in the ByteBuffer input, starting at input.position(). Upon return, the buffer's position will be equal to its limit; its limit will not have changed.
Parameters:
input - the ByteBuffer
Throws:
IllegalStateException - if this Mac has not been initialized.
"
Nothing said about what happens if the input is null.
In that time the IllegalArgumentException will be thrown if pass null pointer:
public class MacUpdate {
public static void main(String[] args) {
try {
//Generate secret key
KeyGenerator kg = KeyGenerator.getInstance("HmacSHA1");
SecretKey key = kg.generateKey();
//Instantiate Mac
Mac theMac = Mac.getInstance("HmacSHA1");
theMac.init(key);
//do test
ByteBuffer buf = null;
theMac.update(buf);
theMac.doFinal();
} catch(IllegalArgumentException e){
System.out.println(e.toString());//we shouldn'g be here according to spec.
} catch (Exception e){
e.printStackTrace();
}
}
}
The output will be
java.lang.IllegalArgumentException: Buffer must not be null
I guess the spec need to be updated (at least for JDK8).
"
Processes input.remaining() bytes in the ByteBuffer input, starting at input.position(). Upon return, the buffer's position will be equal to its limit; its limit will not have changed.
Parameters:
input - the ByteBuffer
Throws:
IllegalStateException - if this Mac has not been initialized.
"
Nothing said about what happens if the input is null.
In that time the IllegalArgumentException will be thrown if pass null pointer:
public class MacUpdate {
public static void main(String[] args) {
try {
//Generate secret key
KeyGenerator kg = KeyGenerator.getInstance("HmacSHA1");
SecretKey key = kg.generateKey();
//Instantiate Mac
Mac theMac = Mac.getInstance("HmacSHA1");
theMac.init(key);
//do test
ByteBuffer buf = null;
theMac.update(buf);
theMac.doFinal();
} catch(IllegalArgumentException e){
System.out.println(e.toString());//we shouldn'g be here according to spec.
} catch (Exception e){
e.printStackTrace();
}
}
}
The output will be
java.lang.IllegalArgumentException: Buffer must not be null
I guess the spec need to be updated (at least for JDK8).
- duplicates
-
JDK-4954458 (spec) incomplete spec for javax.crypto Missing @throws IllegalArgumentException.
- Closed