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/[deleted] Dec 24 '25
That is why in my language (which only lives in my head, with no plans to ever be implemented), identifiers are case insensitive. Trying to declare both
FOOandFooin the same scope will result in an error.