# HG changeset patch # User jlahoda # Date 1463406117 -7200 # Node ID d934635453ada97e0bfdc7475c01f9610ef1e89c # Parent 3f450a95c68fcc4919ee5f0461a6fe0a984987a2 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 diff -r 3f450a95c68f -r d934635453ad langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java --- 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 diff -r 3f450a95c68f -r d934635453ad langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties --- 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=\ diff -r 3f450a95c68f -r d934635453ad langtools/test/tools/javac/unicode/Unmappable.java --- 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 * diff -r 3f450a95c68f -r d934635453ad langtools/test/tools/javac/unicode/Unmappable.out --- 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