United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6717241 : some diagnostic argument is prematurely converted into a String object

Details
Type:
Enhancement
Submit Date:
2008-06-20
Status:
Closed
Updated Date:
2011-05-17
Project Name:
JDK
Resolved Date:
2011-05-17
Component:
tools
OS:
linux
Sub-Component:
javac
CPU:
unknown
Priority:
P4
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Relates:
Relates:

Sub Tasks

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
EVALUATION

Fixing this is crucial for improving diagnostic support in javac.
                                     
2008-06-20
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)
                                     
2008-06-20
SUGGESTED FIX

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



Hardware and Software, Engineered to Work Together