Uploaded image for project: 'Google Code-in'
  1. Google Code-in
  2. GCI-262

Should not rely on default encoding

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Should
    • Resolution: Fixed
    • Labels:
    • Complexity:
      Low

      Description

      We should not rely on default encoding for these classes:

      Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behaviour to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly.
      
      Using classes and methods that rely on the default system encoding can result in code that works fine in its "home" environment. But that code may break for customers who use different encodings in ways that are extremely difficult to diagnose and nearly, if not completely, impossible to reproduce when it's time to fix them.
      
      This rule detects uses of the following classes and methods:
      
      FileReader
      FileWriter
      
      String constructors with a byte[] argument but no Charset argument
      String(byte[] bytes)
      String(byte[] bytes, int offset, int length)
      String.getBytes()
      String.getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)
      InputStreamReader(InputStream in)
      OutputStreamWriter(OutputStream out)
      ByteArrayOutputStream.toString()
      
      Some Formatter constructors
      Formatter(String fileName)
      Formatter(File file)
      Formatter(OutputStream os)
      
      Some Scanner constructors
      Scanner(File source)
      Scanner(Path source)
      Scanner(InputStream source)
      
      Some PrintStream constructors
      PrintStream(File file)
      PrintStream(OutputStream out)
      PrintStream(OutputStream out, boolean autoFlush)
      PrintStream(String fileName)
      
      Some PrintWriter constructors
      PrintWriter(File file)
      PrintWriter(OutputStream out)
      PrintWriter(OutputStream out, boolean autoFlush)
      PrintWriter(String fileName)
      
      IOUtils methods which accept an encoding argument when that argument is null, and overloads of those methods that omit the encoding argument

        Attachments

          Activity

            People

            Assignee:
            navareth Bartłomiej Rasztabiga
            Reporter:
            dkayiwa Daniel Kayiwa
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: