JDK-6722234 : javac diagnostics need better integration with the type-system
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6,7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2008-07-03
  • Updated: 2012-01-13
  • Resolved: 2012-01-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b62Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Javac diagnostics do not cope well with the type-system. Javac diagnostic system falls short when representing complex JDK 5 types such as intersection types, captured types, type-variables and so on. 

Examples:

1)  ********************

CODE:

class Foo<T extends String> {
  <T extends Integer> void foo(T t) {           
      test(t);
  }
  void test(T t) {}
} 

RESULTS:

Test.java:6: test(T) in Foo<T> cannot be applied to (T)
      test(t);
      ^
1 error

PROBLEM:
The diagnostic is ambiguous (as also reported in 5101303). Please add some info about the site in which the type-variable has been declared.

2) **********************************************

CODE: 

import javax.tools.*;
class Test {
  static void test() {
   JavaCompiler compiler = null;
   compiler.getTask(null, null, null,
                 "Bad Argument", null, null);
} }

RESULTS:

Test.java:6: getTask(java.io.Writer,javax.tools.JavaFileManager,
javax.tools.DiagnosticListener<? super javax.tools.JavaFileObject>,
java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.String>,
java.lang.Iterable<? extends javax.tools.JavaFileObject>) in javax.tools.
JavaCompiler cannot be applied to (<nulltype>,<nulltype>,<nulltype>,
java.lang.String,<nulltype>,<nulltype>)
    compiler.getTask(null,null,null,"Bad Argument",null,null);
             ^
1 error

PROBLEMS

Too verbose. Can be improved by dropping qualified names in favor of simple names.

3) **********************************************************************

CODE:

interface List<E> {}

class Test {
    <T> void merge(List<T> l1, List<T> l2) {}
    void test(List<? extends Test> list) {
	merge(list, list);
    }
}

RESULTS:

Test.java:6: <T>merge(List<T>,List<T>) in Test cannot be applied to (List<capture#173 of ? extends Test>,List<capture#228 of ? extends Test>)
	merge(list, list);
	^
1 error

PROBLEMS

The diagnostic is too unfriendly for a non-generics guru.

Comments
SUGGESTED FIX A webrev of this fix is available at the following URL: http://hg.openjdk.java.net/jdk7/tl/langtools/rev/d402db1005ad
21-05-2009

EVALUATION This formatter can be built on top of Type/Symbol visitor printers (see CR 6735840)
11-08-2008

EVALUATION Planning to add a list of 'where-clauses' so that contents of the diagnostic message can be better understood even by a non-experienced java programmer. The where clause reports info e.g. about a type-variable bounds and other useful things like that. This will allow for more descriptive diagnostics, without requiring the user to read tons of info (actually we plan enable the generation of such where clauses on-demand - so that the user can decide whether he needs more details about a given diagnostic - obviously I expect IDE developers to play a lot better with this feature)
03-07-2008