Community
Participate
Working Groups
I noticed that when I delete source files in eclipse, the class files remain behind, which cause unexpected problems when I later import other source files with errors (I am a grader, and when I import a student's work that doesn't work (compiler errors), the program will still run off the old class files from the last student's work). It seems that eclipse should also delete any compiled resources along (or at least provide an option to do so).
Moving to JDT Core for comment
When a source file is deleted, the next build action should delete associated classfiles.
When the next build runs corresponding .class files are definitely deleted for every deleted source file. Did you disable Auto-build? If you did then you should hit Crtl-B to invoke a build. Do you have a reproduceable testcase in which .class files are left around after a build?
I assume what you mean by auto build is configued at Windows->Preferences- >Workbench-> Perform build automatically on resource modification? I have that box checked, and this is the behavior that I observed, I have a set of valid source files from a student's assignment. It runs properly. I delete all the source files, import another student's work, upon which I immediately notice many compiler errors. I wondered if eclipse would still run the project, so I hit ctrl - F11 to Run-last-configuration, and the program ran and gave the usual output that looked identical to the previous student's work. I assume that eclipse run the last compiled valid class files, even thought the current source files are invalid. A few disclaimers: I have only tested it once, and I didn't dig deep to find out if this is truely the case. For example, the compiler error might be in irrelevant files, so they don't affect the run itself. One possibility, I think, is that when I delete the files, eclipse doesn't delete the compiled class files, and when I import another set of files, because eclipse doesn't consider this to be "modification" (yes?), it doesn't auto-build, so the previous class files still run. Of course, I haven't looked at the source code, so this is entirely my assumption. Let me know if I should try to reproduce this behavior.
I believe the 'new' source files you imported had compile errors that did not prevent them from running the test. The Eclipse compiler generates valid executable .class files even when the source file has compile errors. Depending on the severity of the compile error, you may be able to run all but 1 method without noticing the error. Reopen the PR if you see that the timestamps on the .class files were not updated when you imported new code.
I haven't got the chance to test out the "bug" yet. But is there any reason to wait until the next build to clean up the compiled files? It seems oftly dangerous to me (what if I decided to launch the class files outside of eclipse, and I have auto-build disabled?) IMHO, wouldn't it be better to delete all "associated" files (class files, and any other things that may be compiled) at the time that the source files are deleted? That seems to be the intuition from the perspective of the user (me). It shouldn't be too time-consuming (and even if it is, the user, by virtue of having initiated the command, would expect that).
The purpose of auto-build is let users control when builds happen. If you want immediate reaction then do not turn it off. Its that simple.