JDK-8339308 : Case Sensitivity Issue in Compiling Classes Named Sample and sample
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 22
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2024-08-29
  • Updated: 2024-08-31
  • Resolved: 2024-08-30
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
When compiling a Java file containing multiple classes, including `Sample` and `sample`, only one of the compiled files is generated (e.g., `Sample.class`). The expected behavior is that both `Sample.class` and `sample.class` should be generated, as Java is case-sensitive. 


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a Java file with the following content:
   ```java
   class Sample {
       public static void main(String[] args) {
           System.out.println("Hello World");
       }
   }
   class sample {
       public static void main(String[] args) {
           System.out.println("Hello World");
       }
   }```
2. Compile the file using javac Filename.java.
3. Check the generated .class files

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Files with name Sample.class and sample.class should be present.
ACTUAL -
only one file is present.

FREQUENCY : always



Comments
Presumably this is happening on an O/S with a case-insensitive file system. You can confirm this by adding the `-Xlint:output-file-clash` flag which was added in PR #12754 (https://github.com/openjdk/jdk/pull/12754): $ javac -Xlint:output-file-clash Filename.java warning: [output-file-clash] output file written more than once: /Users/archie/proj/jdk/bugs/8339308/sample.class As described in that PR, there's not much else the compiler can do about this. The recommendation therefore is that if you have a case-insensitive filesystem, you should always be using the `output-file-clash` lint flag. Resolving this bug as a duplicate of JDK-8296656.
30-08-2024