I recently discovered that relying on default encoding of JVM causes bugs. I should explicitly use specific encoding ex. UTF-8 while working with String, InputStreams etc.
I have a huge codebase to scan for ensuring this. Could somebody suggest me some simpler way to check this than searching the whole codebase.
Thanks
Nayn
Not a direct answer, but to ease the job it’s good to know that in a bit decent IDE you can just search for used occurrences of
InputStreamReader,OutputStreamWriter,String#getBytes(),String(byte[]),Properties#load(),URLEncoder#encode(),URLDecoder#decode()and consorts wherein you could pass the charset and then update accordingly. You’d also like to search forFileReaderandFileWriterand replace them by the first two mentioned classes. True, it’s a tedious task, but worth it and I’d prefer it above relying on enrivonmental specifics.In Eclipse for example, select the project(s) of interest, hit Ctrl+H, switch to tab Java Search, enter for example
InputStreamReader, tick the Search For option Constructor, choose Sources as the only Search In option, and execute the search.