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


##########
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:
   💡 **Guard against null `code`**
   
   `diagnostic.getCode()` may return `null` (the `Diagnostic` contract allows 
it). When it does, this line produces `"WARNING: null"` — a non-blank string 
that passes the `isBlank()` check below and gets logged verbatim to users.
   
   ```suggestion
                   message = diagnostic.getKind() + (code != null ? ": " + code 
: "");
   ```



##########
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:
   💡 **Add a `verify.groovy` to assert the IT actually tests something**
   
   `invoker.goals = clean compile` only asserts a zero exit code. On any JDK 
that does not trigger `CompletionFailure`, the build succeeds trivially and the 
test proves nothing. A `verify.groovy` that checks the build log for the 
expected deprecation warning would confirm the fix works and guard against 
regressions:
   
   ```groovy
   // src/it/MCOMPILER-1150/verify.groovy
   def log = new File(basedir, 'build.log').text
   assert log.contains('deprecated') : 'Expected deprecation warning in build 
log'
   ```
   
   Note: the exact assertion depends on what the fixed code now emits — adjust 
the `contains` expression to match the actual fallback 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