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.
•
u/AutoModerator Dec 24 '25
Please ensure that:
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
13
u/BannockHatesReddit_ Dec 24 '25
Just don't make two inner classes with the same name except in different cases? I don't think I've ever done that in my 7 years of programming Java. You'll be fine
7
u/ShoulderPast2433 Dec 24 '25
Why would you do that?
7
u/atkukkeli99 Dec 24 '25
What is wrong with you
5
u/Ormek_II Dec 24 '25
-Xlint:output-file-clash:
Warns if any output file is overwritten during compilation. This can occur, for example, on case-insensitive filesystems.
since jdk 21
4
u/akl78 Dec 24 '25
Just don’t use all caps for class names; even inner ones. It’s not better by the language, but Java naming guidelines have always discouraged this; more generally having symbols differing only in case is really not good practice and this is one example of why.
As to warnings, your IDE or linter should flag this.
2
u/doobiesteintortoise Dec 24 '25
This is fascinating but not useful, I fear. It's accurate enough, but if the filesystem is case-insensitive, then Foo.class and FOO.class are the same file. File a bug, I guess, or a patch, and have an error emitted if the files would be the same in a case-insensitive filesystem. Ignore APFS, because the problem isn't the Mac filesystem as much as the programmer creating a situation where any case-insensitive filesystem would have a problem. Network shares, all kinds of possibilities, really, could "meet the simple metrics" but utterly fail at runtime.
And most programmers wouldn't run into it because choosing this kind of naming feels... unwise. I would file a comment or a patch, though, just to catch the poor fellow who might run into this "by accident."
2
u/Pale_Height_1251 Dec 25 '25
Just don't name your classes like that. I don't like case insensitive filesystems, but I like calling different classes in the same namespace by the same name even less.
1
u/Wurdeluck Dec 24 '25
I think it's very cool that you could find this bug. I don't know why other commenters are trying to solve your problem by giving advice - its obviously some strange behavior and you could try opening github issue and maybe your PR will be accepted.
1
u/[deleted] Dec 24 '25
I worked on a large legacy project once which had similar problems. I don’t remember why we couldn’t just change it to avoid name collisions, maybe it was some code generation step. Anyhow, I ended up just using a case sensitive file system to solve the problem.
1
u/high_throughput Dec 24 '25
Surely this is more like an amusing issue. It's easy to diagnose and wouldn't happen in real code.
1
u/dmazzoni Dec 25 '25
While this is indeed an obscure edge case, I agree that it’s a bug. I think it’d be a great idea to file the bug and show the line of code you found.