Bug 32889

Summary: False error about an unresolved type in source editor
Product: [Eclipse Project] JDT Reporter: Stefan Matthias Aust <sma>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: 2.1   
Target Milestone: 3.2 M4   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Stefan Matthias Aust CLA 2003-02-25 04:04:09 EST
I'm unsure whether this is a Core or UI problem.  It's reproducable with 2.1RC1.

Create a project and add the two classes shwon below.  The code will be compiled
without errors.  However, if you open an editor on A, there's an error that C
can't be resolved or isn't a valid type.  There's no error shown in the task
view though.  It doesn't matter whether A and B are public classes or not. 
However, if you make C also public (which of course is an error) the task view
also shows the "C cannot resolved" error.

// A.java
class A {
 C c;
}

// B.java
class B {
}
class C {
}

This is a minimal example but the problem gets really annoying for larger
projects like Coco/R which has a lot of small helper classes combined in a
single compilation unit.

Even if you switch of "Analyse annotations while typing" you cannot select "C"
and press "F3" to goto its definition.  There's an error shown in the
workbench's status line.
Comment 1 Philipe Mulet CLA 2003-02-25 04:34:21 EST
Secondary types in compilation units are known to cause some grief.
As soon as A will refer to B, C will be found from there on. 

Note that other tools could also miss C, e.g. use a command line compiler, and 
tell it to compile A.java with B.java available only on the classpath...
C will not be found as it isn't matching a corresponding file name, or hasn't 
been discovered while resolving a reference to B prior to this point.

Using secondary types outside a compilation unit is really not a good thing to 
do, and in order to handle this better we would have to eagerly open and parse 
all available types to see if a secondary type is a good match. Performance 
wise this would be deadly.

Comment 2 Stefan Matthias Aust CLA 2003-02-25 05:15:34 EST
Philippe is right that this is bad style.  However, is legal bad style and it is
very irritating that errors are generated.  With Coco/R, the right error bar is
red.  Perhaps the error should be only a warning or should otherwise indicate
that it might be a false error, perhaps even sugesting to add a reference to the
compilation unit's primary class.
Comment 3 Philipe Mulet CLA 2003-02-25 05:31:26 EST
Bad style doesn't mean we should not tolerate it anyway (life would be so 
boring if we only had to compile correct code<g>). What I wanted to point out 
is that depending on involved tools, there is a chance to recreate the 
same 'false' problem, it is only a matter of how hard you try to break it.

Using the command line compiler, the same issue can happen (as I said in 
earlier comment). Or consider our incremental builder, and previously discard 
the C.class from the output folder. Basically, it relies on the fact someone 
told it to produce C.class at some earlier stage. 

The source model is not that different with respect to this issue, and its 
setup makes it quite easily fall into this trap.

Comment 4 Philipe Mulet CLA 2003-03-04 10:36:43 EST
Deferring
Comment 5 Philipe Mulet CLA 2003-04-03 07:10:35 EST
Dup
Comment 6 Philipe Mulet CLA 2003-04-03 07:10:51 EST

*** This bug has been marked as a duplicate of 32505 ***
Comment 7 Frederic Fusier CLA 2007-04-02 07:27:01 EDT
Verified for 3.2 using M20060629-1905.