• Icon: Sub-task Sub-task
    • Resolution: Delivered
    • Icon: P4 P4
    • 21
    • 21
    • tools

      A new compiler lint flag, `output-file-clash`, enables detection of output file clashes. An output file clash is when the compiler intends to write two different output files, but due to the behavior of the operating system, these files end up being written to the same underlying file.

      This usually happens due to case-insensitive file systems. For example, a class like this would cause two class files to be written to the same file, `Test$Inner.class`:

      ```java
      public class Test {
          class Inner {
          }
          class INNER {
          }
      }
      ```
      However, this problem can also happen when the file system "normalizes" file names. For example, on macOS, compiling this class will generate such a clash:
      ```java
      public class Test {
          interface Cafe\u0301 {
          }
          interface Caf\u00e9 {
          }
      }
      ```
      The reason is that `\u0301` is the Unicode character "Combining Acute Accent" which means "add an accent over the previous character". MacOS normalizes the letter `e` followed by a `\u0301` into a Unicode `\u00e9`, that is, `é`. However, the Java language treats these the two names, `Cafe\u0301` and `Caf\u00e9`, as distinct.

      Compiling the example above on macOS with `-Xlint:output-file-clash` will now generate a warning like this:
      ```
          warning: [output-file-clash] output file written more than once: /home/test/Test$Café.class
      ```

            acobbs Archie Cobbs
            acobbs Archie Cobbs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: