desruisseaux commented on code in PR #1160:
URL: 
https://github.com/apache/maven-compiler-plugin/pull/1160#discussion_r4228416375


##########
src/main/java/org/apache/maven/plugin/compiler/DiagnosticLogger.java:
##########
@@ -114,7 +119,25 @@ private String relativize(String file) {
      */
     @Override
     public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
-        String message = diagnostic.getMessage(locale);
+        String message;
+        String code = diagnostic.getCode();
+        try {
+            message = diagnostic.getMessage(locale);
+        } catch (RuntimeException e) {
+            /*
+             * Some JDK versions may fail while formatting a diagnostic if a 
referenced class has an
+             * annotation type that is not on the classpath. CompletionFailure 
is a RuntimeException; the
+             * compiler can still emit a useful fallback representation.
+             */
+            if (loggedFormattingFailures.add(code)) {
+                logger.debug("Cannot format compiler diagnostic; falling back 
to its string representation.", e);
+            }
+            try {
+                message = diagnostic.toString();
+            } catch (RuntimeException e2) {

Review Comment:
   Remove this block. There is no guarantee that `toString()` will produce a 
useful message since there is nothing about that in `Diagnostic` interface 
contract. Instead, use unconditionally the next fallback. Then replace or 
remove the _"falling back to its string representation"_ text in above log 
message.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to