Bug 35098 - Delete compiled class files when deleting source file.
Summary: Delete compiled class files when deleting source file.
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 2.1 RC3   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-03-15 18:51 EST by Peter Chan CLA
Modified: 2003-03-24 10:20 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Chan CLA 2003-03-15 18:51:27 EST
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).
Comment 1 Erich Gamma CLA 2003-03-17 19:37:50 EST
Moving to JDT Core for comment
Comment 2 Philipe Mulet CLA 2003-03-18 04:38:44 EST
When a source file is deleted, the next build action should delete associated 
classfiles. 
Comment 3 Kent Johnson CLA 2003-03-18 11:28:59 EST
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?
Comment 4 Peter Chan CLA 2003-03-18 11:46:04 EST
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.
Comment 5 Kent Johnson CLA 2003-03-18 13:09:20 EST
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.
Comment 6 Peter Chan CLA 2003-03-23 13:39:56 EST
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).
Comment 7 Kent Johnson CLA 2003-03-24 10:20:26 EST
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.