-
Enhancement
-
Resolution: Fixed
-
P4
-
None
-
b17
The modified Convert.quote function is used by Pretty here [1], and the new behaviour means that when pretty-printing char literals the wrong quoting happens.
I don't know if this results in any user-visible issues, I think pretty-printing is mainly used for debugging. But it would still be nice to clear this up so the pretty printed output was valid Java source.
Demo:
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.Context;
import java.nio.charset.StandardCharsets;
import java.util.List;
public class T {
public static void main(String[] args) {
var context = new Context();
new JavacFileManager(context, true, StandardCharsets.UTF_8);
var make = TreeMaker.instance(context);
for (var l : List .of('\'', '\"', "\"", "\'")) {
System.err.printf("%s -> %s\n", l, make.Literal(l));
}
}
}
/google/data/ro/projects/java-platform/linux-amd64/jdk-22-latest/bin/java --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED T
' -> '\''
" -> '\"'
" -> "\""
' -> "\'"
' -> '''
" -> '\"'
" -> "\""
' -> "'"
The case of a character literal for a single quote shows the pretty printed output is ''', which is incorrect.
[1] https://github.com/openjdk/jdk/blob/2461263aac35b25e2a48b6fc84da49e4b553dbc3/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/Pretty.java#L1470
- links to
-
Commit(master) openjdk/jdk/083b9808
-
Review(master) openjdk/jdk/21116