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


##########
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:
   Fixed in `c8d79739b8a3c88a5105e6f878d48569783a1b0f`. The final fallback now 
appends the diagnostic code only when non-null, and a regression covers a null 
code with both formatting methods throwing. `mvn -Dtest=DiagnosticLoggerTest 
test` passes (4 tests); the targeted MCOMPILER-1150 integration test also 
passes.



##########
src/it/MCOMPILER-1150/invoker.properties:
##########
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals = clean compile

Review Comment:
   Fixed in `c8d79739b8a3c88a5105e6f878d48569783a1b0f`. Added `verify.groovy` 
to assert that the diagnostic-formatting fallback actually ran in the Invoker 
build log, rather than accepting only a zero exit code. Validation: `mvn 
-Prun-its -Dinvoker.test=MCOMPILER-1150 verify` passed (1 targeted IT; 23 
module unit tests in the build).



-- 
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