Bug 336120 - Deleting .class files from bin folders causes ClassNotFoundExceptions for projects dependent on other projects
Summary: Deleting .class files from bin folders causes ClassNotFoundExceptions for pro...
Status: VERIFIED NOT_ECLIPSE
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6.1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-02 13:08 EST by dougdigdag CLA
Modified: 2011-03-07 06:44 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dougdigdag CLA 2011-02-02 13:08:12 EST
Build Identifier: 20100917-0705

If a project is dependent upon another project, and the projects' compiled .class files are deleted outside of Eclipse, then when the projects are reopened in Eclipse, code in the dependent project cannot resolve any classes declared in the project it's dependent on.  This problem manifests itself as ClassNotFoundExceptions.

The obvious solution might be simply to leave the .class files alone, but unfortunately this is not always possible.  As an example, consider a collaborative development environment, when only the source code of a project and not its compiled binary files are checked into and out of a version control system.

The problem can be fixed by running "Project ~ Clean", or by introducing a syntax error, building, removing the error, and building again.  But this can be cumbersome in a project with many dependencies and frequent changes.

Reproducible: Always

Steps to Reproduce:
1. Start Eclipse, create a new workspace.

2. Right click on the Package Explorer pane.  In the context menu, select "New ~ Java Project".

3. On the New Java Project dialog, enter the value "Project1" in the Project Name box and click the Finish button.

4. In the Package Explorer pane, click the plus-sign button next to the newly created "Project1" project.

5. Right-click on the "src" folder and select New ~ Class from the context menu.

6. On the New Java Class dialog, enter the value "Class1" in the Name box and click the Finish button.

7. Right click on the Package Explorer pane.  In the context menu, select "New ~ Java Project".

8. On the New Java Project dialog, enter the value "Project2" in the Project Name box and click the Finish button.

9. In the Package Explorer pane, right-click on the "Project2" node and select "Build Path ~ Configure Build Path" from the context menu.

10. On the Properties for Project2 dialog, click the Projects tab, then click the Add button.

11. On the Required Project Selection dialog, click the checkbox for "Project1" and then the OK button.

12. In the Package Explorer pane, click the plus-sign button next to the newly created "Project2" project.

13. On the Required Project Selection dialog, click OK.

14. In the Package Explorer pane, click the plus-sign button next to the "Project2" project.

15. Right-click on the "src" folder and select New ~ Class from the context menu.

16. On the New Java Class dialog, enter the value "Class2" in the Name box, click the check box next to "public static void main(String[] args)", and click the Finish button.

17. In the Editor pane, in the "main()" function, enter the text "Class1 class1Test = new Class1();" and save the file.

18. With Project2 selected in the Package Explorer, click the Run button on the toolbar and click OK on the Save and Launch dialog.  A warning (but no errors) will appear in the Problems pane.

19. Exit Eclipse.

20. From the operating system, navigate to the folders "Project1\bin" and "Project2\bin", wherever they reside, and delete their contents (but not the folders themselves).  For these projects, a single .class file will be present in each folder.

21. Start Eclipse again.  The previous workspace should be loaded automatically.

22. Select the "Project2" node in the Package Explorer and then click the Run button. 

23. An error dialog will appear, stating "Could not find the main class: Class2.  Program will exit.".  A ClassNotFoundException will also appear in the console pane.

24. This problem can be worked around by selecting "Project ~ Clean" from the main menu, or by intentionally introducing a syntax error into Class1.java, building, removing the error, and building again.
Comment 1 Markus Keller CLA 2011-02-02 13:36:14 EST
I don't think we should do anything here. If you touch the bin folder outside of Eclipse, you're on your own. Project > Clean... is the recommended way to recover.

Moving to JDT/Core to close.
Comment 2 Ayushman Jain CLA 2011-02-03 01:00:48 EST
(In reply to comment #0)
> Build Identifier: 20100917-0705
> 
> If a project is dependent upon another project, and the projects' compiled
> .class files are deleted outside of Eclipse, then when the projects are
> reopened in Eclipse, code in the dependent project cannot resolve any classes
> declared in the project it's dependent on.  This problem manifests itself as
> ClassNotFoundExceptions.

I think this is a very obvious implication of what you're trying to do here, and there's nothing eclipse can do about it. This is like a command line "java Test" when Test.class has been deleted. This is meant to fail.

Jay, you have the final word.
Comment 3 Jay Arthanareeswaran CLA 2011-02-03 01:18:18 EST
No, I don't think we can do anything here.
Comment 4 Satyam Kandula CLA 2011-03-07 06:44:58 EST
Verified for 3.7M6