Bug 135729 - Cant resolve class A, if class A was enhanced in a post compilation step
Summary: Cant resolve class A, if class A was enhanced in a post compilation step
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 RC2   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 131791 138361 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-04-08 18:22 EDT by Erik Bengtson CLA
Modified: 2006-04-28 14:02 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Bengtson CLA 2006-04-08 18:22:06 EDT
Eclipse 3.2 M5, M6 (cant say if in previous milestones it worked or not)

Used to work in Eclipse 2 up to 3.1.2

I have a project that uses a project builder that enhances persistent classes (JDO), adding the implementation of PersistenceCapable interface to these classes. After compilation and enhancement, you are able to run the application. The problem starts when we change one class that has a reference to these enhanced classes. You edit the source of the class and save it. After saving the class you get "The type org.jpox.samples.city.Country cannot be resolved. It is indirectly referenced from required .class files". "org.jpox.samples.city.Country" was enhanced in a previous compile step.


To reproduce:

class A
{
String a;
}

class B
{
A a;
}

1) Compile A and B classes.
2) Enhance class A (you can use JPOX if you like, or some other tool to modify the bytecode).
3) Optional: Run B
4) Edit B and save. The issue should show up now.

Workaround: Rebuild the project
Comment 1 Philipe Mulet CLA 2006-04-10 05:31:24 EDT
Feels related to bug 129082, which should have been corrected in 3.2M6.
Comment 2 Erik Bengtson CLA 2006-04-10 07:11:51 EDT
Yes it looks like bug 12908. I opened A.class using an hex editor and saved it. That was enough for reproducing the issue. The Class A is still a valid class since I run "javap A" and it worked.

I'm using Version: 3.2.0 Build id: N20060408-0010
Comment 3 Erik Bengtson CLA 2006-04-10 07:13:03 EDT
To correct the above comment: It looks like bug 129082.
Comment 4 Kent Johnson CLA 2006-04-12 13:58:16 EDT
Tried to reproduce but it works fine for me.

So do you have the new option enabled to recreate modified class files? I assume not.

And does A.class still exist in the same place in the directory structure after you've saved it?
Comment 5 Erik Bengtson CLA 2006-04-12 16:21:25 EDT
To reproduce it

1) Downloaded Eclipse Build id: N20060408-0010 or any latest version
2) Create a new java project
3) Create A and B classes.
4) Compile A and B classes.
5) Open and save in an external editor the file A.class
6) Edit in eclipse B and save. The issue should show up now.
Comment 6 Kent Johnson CLA 2006-04-12 16:29:19 EDT
Those are the same steps as before and it works fine for me.

Can you please try it again and tell me if A.class is still in the same place (by looking at it on disk).
Comment 7 Erik Bengtson CLA 2006-04-12 16:36:50 EDT
Yes the file is still there. I was trying to find the "option enabled to recreate modified class file", but could't, everything is set to default
Comment 8 Kent Johnson CLA 2006-04-12 16:39:33 EDT
I'm wondering whether your changes to A.class are corrupting it so we think its not there anymore.

Instead of changing it in an editor, what happens if you replace it with a previous copy that had a different method in it?
Comment 9 Erik Bengtson CLA 2006-04-12 16:45:28 EDT
As I told before javap works, but this is not the issue because if I just open the file with an hex editor and save with no changes, the issue is the same.

Also, In my real work, I use a bytecode enhancer which is very stable and generates fine bytecode, and the issue is the same.

In any case, I just did what you asked and the issue is still the same

The only thing that can be different is the environment so here is mine:

- Windows XP Professional
- Java 1.5.0 06
Comment 10 Kent Johnson CLA 2006-04-13 16:57:04 EDT
Reproduced.

This is a consequence of our change to have ClassFileReaders get the contents of a file using the Core resource API, which checks to see if the file is out of sync. In the past, we got the contents by reading from the raw IO file.

As a workaround, you need to refresh your project after changing the .class files externally.

Philippe - we can force a refresh of the output folder when we detect that the class file is no longer in sync.
Comment 11 Erik Bengtson CLA 2006-04-14 06:23:40 EDT
Glad to see that you were able to reproduce, but refreshing the project is not a good workaround in long term because it recompiles the files again which means that I have to re-enhance the changed files.
Comment 12 Kent Johnson CLA 2006-04-17 10:48:17 EDT
The refresh does not recompile the files again unless the source files have been changed.
Comment 13 Philipe Mulet CLA 2006-04-18 11:46:42 EDT
+1 for 3.2RC2
Comment 14 Kahli Burke CLA 2006-04-21 13:25:18 EDT
See also  bug 131791 which seems like the same issue
Comment 15 Olivier Thomann CLA 2006-04-21 13:27:06 EDT
*** Bug 131791 has been marked as a duplicate of this bug. ***
Comment 16 Kent Johnson CLA 2006-04-21 13:32:05 EDT
This is a straight forward 1 line change to create ClassFileReaders even when
the .class file is out of sync by using the force flag on the call to
getContents().

See org.eclipse.jdt.internal.core.util.Util.newClassFileReader(), changed:
  in = ((IFile) resource).getContents();
to
  in = ((IFile) resource).getContents(true);
Comment 17 Kent Johnson CLA 2006-04-25 10:24:45 EDT
*** Bug 138361 has been marked as a duplicate of this bug. ***
Comment 18 Olivier Thomann CLA 2006-04-28 14:02:53 EDT
Verified with I20060427-1600 for 3.2RC2 (looking at the source code).