I recently updated an app to a targetSdkVersion of 23, and implemented a request for various permissions. My initial attempt using ActivityCompat.requestPermissions() caused an IllegalArgumentException to be thrown from the internals of FragmentActivity:
int REQUEST_CODE_A = 9001;
ActivityCompat.requestPermissions(new String[ {Manifest.permission.WRITE_CONTACTS}, REQUEST_CODE_A); // crashes
java.lang.IllegalArgumentException: Can only use lower 8 bits for requestCode
However, if the request code is between 0-255, everything is fine and the permission request works as expected.
int REQUEST_CODE_B = 101;
ActivityCompat.requestPermissions(new String[ {Manifest.permission.WRITE_CONTACTS}, REQUEST_CODE_B); // works correctly
So the question is, what reasons are there for restricting the possible values of an integer in an API like this? The same information could be supplied using a byte, but a conscious decision has (apparently) been made to use an integer instead. Is this simply a case of allowing future extensibility?