The issue you’re facing occurs because the Java extension in VS Code doesn't always enforce saving the file before running it, depending on your configuration. This is a logical gap, but you can resolve it by adjusting your settings or workflows without enabling auto-save globally. Here's how to address it:
--Open File > Preferences > Settings (or press Ctrl + ,).
--Search for "Save Before Run" in the settings search bar.
--Enable the setting java.debug.saveBeforeStart:
---Go to Extensions > Java Configuration.
---Find Debug: Save Before Start and ensure it’s set to true.
This forces the Java Debugger to save all files before launching.