JDK-6717241 : some diagnostic argument is prematurely converted into a String object
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: unknown
  • Submitted: 2008-06-20
  • Updated: 2011-05-17
  • Resolved: 2011-05-17
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 b33Fixed
Related Reports
Relates :  
Relates :  
Description
Some parts of the compiler pipeline perform an early toString() conversion of the arguments of a diagnostic (or, at times, of the whole diagnostic itself). This can be regarded as a bad practice, as it makes it impossible to exploit the info carried by a diagnostic argument at a later point.

Main examples of this practice:

1) Parser: instead of passing the 'expected' token as a diagnostic argument, it first converts the token into a String and then used this string representation of the token as an argument of the diagnostic.

2) Resolve: a lot of resolution diagnostics actually rely upon the fact that some arguments are strings whose format adhere to some rule. E.g. the diagnostic 'cant.apply.symbol' accepts two String arguments corresponding to the argument list of the expected/found method. Those String are formatted inside the code of Resolve (so that parens surrounding the arguments are inserted, and angular brackets for type-parameters are added if needed).

3) Modifiers (such as 'public', 'private', etc.) are often converted to String they have to be passed as arguments on to a diagnostic. It would be better to keep the modifiers as instances of the class Name, so that they can be distinguished from all other ordinary Java Strings (and, eventually, rendered in a different way by a diagnostic formatter).

Comments
SUGGESTED FIX a webrev of this fix is available at: http://sa.sfbay.sun.com/projects/langtools_data/7/6717241.4
27-06-2008

SUGGESTED FIX 1) Parser and Tokens modified Parser.syntaxError, in order to accept Token arguments and not String arguments. This means that the token 2 String conversion is performed later by the diagnostic formatter/JCDiagnostic.getMessage() 2) Resolve 4 compiler keys affected in compiler.properties: -compiler.err.cant.apply.symbol -compiler.err.cant.apply.symbol.1 -compiler.err.cant.resolve -compiler.err.cant.resolve.location Those keys were in fact expecting some preformatted string arguments (esp. compiler.err.cant.resolve). For this reason I added various alternatives (.1, .2, .3) in order to generate different diagnostic messages depending on whether the symbol to be resolved (i) is a method (parens required) and (ii) has type arguments (angular brackets required). 3) Modifiers Refactoring of Flags.java. Added a method that takes a flags bit mask and returns a list of Name(s)
20-06-2008

EVALUATION Fixing this is crucial for improving diagnostic support in javac.
20-06-2008