-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
None
ADDITIONAL SYSTEM INFORMATION :
The latest Java 8, all operating systems.
A DESCRIPTION OF THE PROBLEM :
Base64.getDecoder().decode() fails to decode mime or url flavors of base64. For many this is surprising not being a direct replacement for org.apache.commons.codec.binary.Base64.decodeBase64 which is base64 format agnostic.
Apparently it is safer to use Base64.getMimeDecoder() to have more base64-format agnostic behavior. This should be either stated in javadocs or Base64.getDecoder().decode() made base64 format agnostic. The reasoning behind the latter is that we've been waiting for such built-in decoder for like 20yrs+ and meanwhile the tendency for JAVA as a language was to become more developer friendly. This is the example where something went wrong on design level and still libraries like apache commons et al serve as a viable facilitators even for such a simple things. What is the profit of Base64.getDecoder() being very picky? For data validation? Even though the input can be perfectly decoded by just ignoring newlines? What's the best way to decode unknown-type base64 data? Try every decoder until no exception is caught?
The last thing is that logging for Base64.getDecoder() is not clear enough - here is the output when trying to decode base64 input of mime type:
Exception in thread "main" java.lang.IllegalArgumentException: Illegal base64 character a
at java.util.Base64$Decoder.decode0(Base64.java:714)
"Illegal base64 character a" - this should be logged as: "Illegal base64 character 0x0A" or "Illegal base64 character 0A", otherwise developer may not know whether 'a' stands for hexadecimal representation of character or it is a character itself. Would also be nice to log the position of unexpected character.
The latest Java 8, all operating systems.
A DESCRIPTION OF THE PROBLEM :
Base64.getDecoder().decode() fails to decode mime or url flavors of base64. For many this is surprising not being a direct replacement for org.apache.commons.codec.binary.Base64.decodeBase64 which is base64 format agnostic.
Apparently it is safer to use Base64.getMimeDecoder() to have more base64-format agnostic behavior. This should be either stated in javadocs or Base64.getDecoder().decode() made base64 format agnostic. The reasoning behind the latter is that we've been waiting for such built-in decoder for like 20yrs+ and meanwhile the tendency for JAVA as a language was to become more developer friendly. This is the example where something went wrong on design level and still libraries like apache commons et al serve as a viable facilitators even for such a simple things. What is the profit of Base64.getDecoder() being very picky? For data validation? Even though the input can be perfectly decoded by just ignoring newlines? What's the best way to decode unknown-type base64 data? Try every decoder until no exception is caught?
The last thing is that logging for Base64.getDecoder() is not clear enough - here is the output when trying to decode base64 input of mime type:
Exception in thread "main" java.lang.IllegalArgumentException: Illegal base64 character a
at java.util.Base64$Decoder.decode0(Base64.java:714)
"Illegal base64 character a" - this should be logged as: "Illegal base64 character 0x0A" or "Illegal base64 character 0A", otherwise developer may not know whether 'a' stands for hexadecimal representation of character or it is a character itself. Would also be nice to log the position of unexpected character.