Bug 239229 - [compiler] Regression bug against Eclipse 3.3: cannot resolve correct import
Summary: [compiler] Regression bug against Eclipse 3.3: cannot resolve correct import
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 critical with 1 vote (vote)
Target Milestone: 3.4.1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 245304 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-07-02 08:08 EDT by Mauro Molinari CLA
Modified: 2008-08-29 04:22 EDT (History)
8 users (show)

See Also:


Attachments
Project that exhibits the problem (13.19 KB, application/octet-stream)
2008-07-03 05:26 EDT, Mauro Molinari CLA
no flags Details
Patch in progress (3.4) (10.97 KB, patch)
2008-07-07 13:06 EDT, Philipe Mulet CLA
no flags Details | Diff
Simple check (958 bytes, patch)
2008-07-07 13:56 EDT, Kent Johnson CLA
no flags Details | Diff
Better patch for 3.4.x (11.81 KB, patch)
2008-07-08 05:40 EDT, Philipe Mulet CLA
no flags Details | Diff
Better patch for 3.4.x take 3 (11.86 KB, patch)
2008-07-08 06:25 EDT, Philipe Mulet CLA
no flags Details | Diff
Proposed patch (16.69 KB, patch)
2008-07-08 07:51 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mauro Molinari CLA 2008-07-02 08:08:38 EDT
Build ID: I20080617-2000

Steps To Reproduce:
As discussed in eclipse.tools.jdt newsgroup...

I have a strange (and serious) problem with Eclipse 3.4. A project of mine seems to have problems compiling some classes.
Eclipse says it can't resolve a package that:
- it does exist
- it is in the same source folder of the classes that try to import a class in it

Precisely, the structure is this:
- src
   - my.package.MyClass
   - my.package.exceptions.AnotherClass

MyClass imports my.package.exceptions.AnotherClass, but the compiler says it can't resolve my.package.execeptions. However, AnotherClass exists and is in that package.
If I edit MyClass, delete "import my.package.exceptions.AnotherClass" then use Organize Imports and save, the error goes away, although sometimes the red markers in the overview rulers remain.

It's a very weird problem, one of those problems I had in the past when I had buildpath problems. But there are no buildpath problems this time. I double checked everything, I even built up all the project from scratch in order to make sure there are no subtle causes to this. But the problem persists.
I cleaned and built the project many times, without success.

The classes that exhibit this problem are always the same.

With Eclipse 3.3.2 there are no problems.

I have prepared a small workspace that exhibits the problem. I'm taking agreements with Philippe Mulet to understand the way to submit this example code, because it's about proprietary code.

Mauro.
Comment 1 Philipe Mulet CLA 2008-07-02 09:21:10 EDT
If truly a regression, then we should address it for 3.4.1
Comment 2 Mauro Molinari CLA 2008-07-03 05:26:10 EDT
Created attachment 106408 [details]
Project that exhibits the problem

I was able to prepare a tiny testcase that shows the problem and I was able to identify the problem. Please see my next comment.
Comment 3 Mauro Molinari CLA 2008-07-03 05:34:37 EDT
First of all, prepare a new empty workspace. Set it up so that you have a 1.6 JRE bounded to JSE 1.6 Execution environment.

Then, unzip the folder "Test bug 239229" in the attached ZIP into your new workspace and import the project in that folder.

Now, have a look at the code:
- com.ost.util.report.FilterConstraintSpecification does not compile because it can't resolve the package com.ost.util.report.exceptions... but that package is there!
- the same for com.ost.util.report.InspectedMatrix
- com.ost.util.report.Matrix<T> and com.ost.util.report.MatrixInspector, instead, don't have problem to resolve that package.

Now, take com.ost.util.report.FilterConstraintSpecification, remove the offending import line, press Ctrl+Shift+O, then save: you'll see that the error vanishes.
Then, invoke Project | Clean... and clean the project: the error will appear again!

This is weird and this is what I observed in my real problem.

But now the funny part...

Open com.ost.util.report.Matrix<T> and see the "@see" line in its Javadoc. First of all, notice that no warning nor error is given for that malformed @see clause (I obviously activated all the Javadoc validation options), although it is clearly wrong.

But now, remove the line containing the "@see" tag and save. Then do a Project | Clean... TADAA! The error "The import com.ost.util.report.exceptions cannot be resolved" on both com.ost.util.report.FilterConstraintSpecification and com.ost.util.report.InspectedMatrix is vanished!

Mauro.
Comment 4 Mauro Molinari CLA 2008-07-03 05:36:53 EDT
(In reply to comment #3)
> This is weird and this is what I observed in my real problem.

I meant: "in my real project"! Sorry for the typo.

Mauro.
Comment 5 Philipe Mulet CLA 2008-07-07 11:18:12 EDT
Reproduced. Problem only occurs when enabling javadoc diagnoses, and after 3.4M6.
Comment 6 Philipe Mulet CLA 2008-07-07 11:20:42 EDT
The error indeed comes from the unbound reference in javadoc:
/**
 * @see exceptions.InvalidRowSizeException
 */

I believe it is related to change for bug 196200.
Comment 7 Philipe Mulet CLA 2008-07-07 11:43:50 EDT
Added ProblemTypeAndMethodTest#test081
Comment 8 Philipe Mulet CLA 2008-07-07 12:33:40 EDT
Simpler testcase:
//p/X.java
package p;
public class X extends zork.Z {
}

//p/Y.java
package p;
import p.zork.Z;
public class Y {
}

//p/zork/Z.java
package p.zork;
public class Z {
}
Comment 9 Philipe Mulet CLA 2008-07-07 13:06:01 EDT
Created attachment 106735 [details]
Patch in progress (3.4)

The problem may occur outside javadoc. Only need a prior reference to missing type which is colliding with subpackage to cause some later confusion.

In particular, I am not yet satisfied with behavior of patch for ProblemTypeAndMethodTest#test081 producing unexpected error:

		"3. ERROR in com\\ost\\util\\report\\Matrix.java (at line 9)\n" + 
		"	throw new InvalidRowSizeException();\n" + 
		"	      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
		"No exception of type InvalidRowSizeException can be thrown; an exception type must be a subclass of Throwable\n"
Comment 10 Kent Johnson CLA 2008-07-07 13:46:20 EDT
Philippe - so this is a case of a MissingType taking precedence over a package that we have yet to find/request ?

We've had similar issues with types that conflict with packages.


Possibly we could handle this by searching for a conflicting package before adding a MissingType to a package's cache... then you wouldn't need to check everytime someone requests a package/type.
Comment 11 Kent Johnson CLA 2008-07-07 13:56:37 EDT
Created attachment 106736 [details]
Simple check
Comment 12 Philipe Mulet CLA 2008-07-08 04:53:48 EDT
My suggested patch is causing lots of regressions. I had thought of checking for conflicting package before adding missing type, but I was under impression this was weaker, as we may not know all packages at that stage (thinking of requested types to come in later). 

Comment 13 Philipe Mulet CLA 2008-07-08 05:40:50 EDT
Created attachment 106796 [details]
Better patch for 3.4.x

Addresses the issues raised by previous patch.
Comment 14 Philipe Mulet CLA 2008-07-08 06:25:52 EDT
Created attachment 106802 [details]
Better patch for 3.4.x take 3
Comment 15 Philipe Mulet CLA 2008-07-08 07:51:47 EDT
Created attachment 106810 [details]
Proposed patch

for HEAD
Comment 16 Philipe Mulet CLA 2008-07-08 07:59:06 EDT
Also added ProblemTypeAndMethodTest#test082-088
Comment 17 Philipe Mulet CLA 2008-07-08 08:00:04 EDT
Released for 3.4.1
Comment 18 Philipe Mulet CLA 2008-07-08 08:00:35 EDT
Released for 3.5M1.
Fixed
Comment 19 Olivier Thomann CLA 2008-08-06 14:32:18 EDT
Verified for 3.5M1 using I20080805-1307
Comment 20 Philipe Mulet CLA 2008-08-27 10:24:03 EDT
*** Bug 245304 has been marked as a duplicate of this bug. ***
Comment 21 Jerome Lanneluc CLA 2008-08-29 04:22:13 EDT
Verified for 3.4.1 using M20080827-2000