Bug 304190 - incorrect generic param in @see in one method stops another compiling
Summary: incorrect generic param in @see in one method stops another compiling
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5.1   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: 3.6 RC1   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-01 06:33 EST by Paul Rooney CLA
Modified: 2010-05-17 03:20 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Rooney CLA 2010-03-01 06:33:26 EST
Build Identifier: M20080911-1700

The below code doesn't compile due to the javadoc comment in method 'bar'.
Referencing the generic method using '@see' without the generic param seems to confuse the compiler.

public class EclipseBug {
  public <E extends Exception> void foo(Class<E> clazz) throws E {
    foo(clazz); //Compile error: Unhandled exception type Exception
  }

  /**  @see EclipseBug#foo(Class) BREAKS 'foo' */
  public void bar() {}
  
  /**  @see EclipseBug#foo(Class<E>) WORKS */
  public void fooBar() {}  
}

Reproducible: Always

Steps to Reproduce:
see details
tested using 1.5 and 1.6 JDK compliance
Comment 1 Srikanth Sankaran CLA 2010-03-01 06:54:59 EST
Reproduced on HEAD. I will investigate this.
Comment 2 Paul Rooney CLA 2010-03-01 06:55:43 EST
Build Identifier is incorrect. 
it should be  20090920-1017
from a download named 'eclipse-java-galileo-SR1-win32.zip'
Comment 3 Srikanth Sankaran CLA 2010-03-01 08:33:54 EST
This worked on 3.5 and is broken already at 3.5M7.
Should check with 3.5 M4 & M5.

Perhaps related to bug#258798 ?
(even though that defect's title is about return types,
it also fixed some issues with exceptions in the
presence of unchecked invocations)

Compare javac & eclipse behavior with the slightly
modified test case:

public class EclipseBug {
    Class c = String.class;
    public <E extends Exception> void foo(Class<E> clazz) throws E {
        foo(clazz); 
        foo(c);
    }
}
Comment 4 Srikanth Sankaran CLA 2010-05-10 08:43:50 EDT
(1) 

public class EclipseBug {
  public <E extends Exception> void foo(Class<E> clazz) throws E {
    throw new Exception();
  }
}

results in "Unhandled exception type Exception". This is because
the method now throws Exception, while it is declared to handle
(by throwing) 'E extends Exception'. Thus the thrown exception
is more generic than the handled exceptions, resulting in an
error.

This situation is analogous to the one in the non generic test case
below:

import java.io.IOException;
public class EclipseBug {
  public  void foo(Class<IOException> clazz) throws IOException {
    throw new Exception(); 
  }
}

(2)  Now consider the test case below:

public class EclipseBug {
  public <E extends Exception> void foo(Class<E> clazz) throws E {
    foo(clazz);
  }

  public void bar(Class clazz) throws Exception {
  	foo(clazz);
  }
}

Considering the invocation of the generic method foo in bar,
given the parameter clazz is of raw type, type inference leads
to the conclusion that EclipseBug#foo could throw Exception
and this case decays into the case (1) above.

(3) Now consider the case in comment#0.

While at first sight, it may appear bizarre that something inside
a comment could result in a compile error somewhere else, what
is happening here is very much similar to case(2). When the
preference Java + Compiler + Javadoc + Process Javadoc is turned
on (default) the compiler will perform structural/syntactic 
analysis inside the javadoc comments. The @see comment in question
is treated as a java doc "method call" (JavadocMessageSend in
compiler parlance) and gets analyzed the same way as an analogous
method call in code (case (2)) leading to the same error.

Thus this case needs to be closed as INVALID as there is no
real bug here.
Comment 5 Jay Arthanareeswaran CLA 2010-05-17 03:20:55 EDT
Verified for 3.6RC1.