r/javahelp • u/__zahash__ • Dec 24 '25
MacOS case-insensitive filesystem silently "loses" compiled .class files
I ran into a frustrating issue where javac silently "loses" a class file on macOS but works perfectly on Linux.
// Main.java
public class Main {
public static class FOO {}
public static class Foo {}
public static void main(String[] args) {
System.out.println(new FOO());
System.out.println(new Foo());
}
}`javac Main.java` generates only `Main.class` and `Main$FOO.class` but not `Main$Foo.class` because APFS is case-insensitive by default.
but on linux, all three class files are being generated.
Same JDK (Temurin 17.0.10), no errors, no warnings, Just silent data loss during compilation.
and when i try to run `java Main` it gives me this error
Exception in thread "main" java.lang.NoClassDefFoundError: Main$Foo (wrong name: Main$FOO)Have you ever experienced this? Is there a way to make javac warn about this?
EDIT: I think I have traced the problem to this line in the openjdk compiler.
it incorrectly assumes that if the path separator is a forward slash "/", then the file system is case sensitive. but apple's APFS is case insensitive.
View all comments
Show parent comment
1
u/Big_Green_Grill_Bro Dec 24 '25
Java is specifically case sensitive. Class Foo and class foo are distinctly different classes. The issue is with the underlying file system being case insensitive. During compile time, the compiler compiles and writes the first class to disk. The compiler then compiles and writes the second file to disk. The case insensitive file system is then overwriting the Foo.class file with the contents of the foo.class file.
The issue is that OP is using case sensitive language and compiler on a case insensitive filesystem. That's not a problem with Java, that's a known limitation of the underlying case insensitive filesystem, which OP is choosing to ignore.
OP is 100% being dumb in this contrived case. If you want Foo.class and foo.class to work regardless of the underlying filesystem, then package them in a JAR file, which is case sensitive.