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
3
u/astervista Dec 24 '25
If java was created with naming standards in mind (or at least case insensitiveness), it would have thrown an error at compile time. Naming conventions are a guideline, but are not a rule. And this error could happen in real life with correct naming conventions (think of a class NoteBook and Notebook, one is a book of notes and the other is a log for personal notes).
So is what OP is doing stupid? Probably. Is it still a bug? I would say so. It is unintended and it is a defect.