8078559: Update error message to indicate illegal character when encoding set to ascii
authorjlahoda
Mon, 16 May 2016 15:41:57 +0200
changeset 38511 d934635453ad
parent 38510 3f450a95c68f
child 38512 c71e1cdd6674
8078559: Update error message to indicate illegal character when encoding set to ascii Summary: When an input character cannot be decoded, include it in the produced error Reviewed-by: jjg
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties
langtools/test/tools/javac/unicode/Unmappable.java
langtools/test/tools/javac/unicode/Unmappable.out
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java	Mon May 16 15:41:20 2016 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java	Mon May 16 15:41:57 2016 +0200
@@ -380,13 +380,17 @@
                 dest = CharBuffer.allocate(newCapacity).put(dest);
             } else if (result.isMalformed() || result.isUnmappable()) {
                 // bad character in input
+                StringBuilder unmappable = new StringBuilder();
+                int len = result.length();
 
-                log.error(new SimpleDiagnosticPosition(dest.limit()),
-                          "illegal.char.for.encoding",
-                          charset == null ? encodingName : charset.name());
+                for (int i = 0; i < len; i++) {
+                    unmappable.append(String.format("%02X", inbuf.get()));
+                }
 
-                // skip past the coding error
-                inbuf.position(inbuf.position() + result.length());
+                String charsetName = charset == null ? encodingName : charset.name();
+
+                log.error(dest.limit(),
+                          Errors.IllegalCharForEncoding(unmappable.toString(), charsetName));
 
                 // undo the flip() to prepare the output buffer
                 // for more translation
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Mon May 16 15:41:20 2016 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties	Mon May 16 15:41:57 2016 +0200
@@ -522,8 +522,9 @@
 compiler.err.illegal.char=\
     illegal character: ''{0}''
 
+# 0: string, 1: string
 compiler.err.illegal.char.for.encoding=\
-    unmappable character for encoding {0}
+    unmappable character (0x{0}) for encoding {1}
 
 # 0: set of modifier, 1: set of modifier
 compiler.err.illegal.combination.of.modifiers=\
--- a/langtools/test/tools/javac/unicode/Unmappable.java	Mon May 16 15:41:20 2016 +0200
+++ b/langtools/test/tools/javac/unicode/Unmappable.java	Mon May 16 15:41:57 2016 +0200
@@ -1,6 +1,6 @@
 /*
  * @test /nodynamiccopyright/
- * @bug 4767128 5048557 5048773
+ * @bug 4767128 5048557 5048773 8078559
  * @summary diagnose encoding errors in Java source files
  * @author gafter
  *
--- a/langtools/test/tools/javac/unicode/Unmappable.out	Mon May 16 15:41:20 2016 +0200
+++ b/langtools/test/tools/javac/unicode/Unmappable.out	Mon May 16 15:41:57 2016 +0200
@@ -1,2 +1,2 @@
-Unmappable.java:12:18: compiler.err.illegal.char.for.encoding: ascii
+Unmappable.java:12:18: compiler.err.illegal.char.for.encoding: E4, ascii
 1 error