JDK 14 RFR of JDK-8226785: MandatoryWarningHandler.java contains implementation of Object.equals functionality

Joe Darcy joe.darcy at oracle.com
Wed Jun 26 01:04:15 UTC 2019


Hello,

Noticed while doing some other work, the javac class 
MandatoryWarningHandler.java contains a local copy of of the logic of 
the two-argument Objects.equals method. As a refactoring, the library 
code should be used instead.

The method in MandatoryWarningHandler is named "equal" rather than 
"equals" and escaped previous passes to replace independent 
implementations of this logic (JDK-7041136).

Patch below.

Thanks,

-Joe

diff -r dd697048684f 
src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java
--- 
a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java 
Tue Jun 25 21:33:24 2019 +0000
+++ 
b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/MandatoryWarningHandler.java 
Tue Jun 25 18:02:43 2019 -0700
@@ -26,6 +26,7 @@
  package com.sun.tools.javac.util;

  import java.util.HashSet;
+import java.util.Objects;
  import java.util.Set;
  import javax.tools.JavaFileObject;

@@ -147,7 +148,7 @@
                  deferredDiagnosticArg = currentSource;
              } else if ((deferredDiagnosticKind == 
DeferredDiagnosticKind.IN_FILE
                          || deferredDiagnosticKind == 
DeferredDiagnosticKind.ADDITIONAL_IN_FILE)
-                       && !equal(deferredDiagnosticSource, 
currentSource)) {
+                       && !Objects.equals(deferredDiagnosticSource, 
currentSource)) {
                  // additional errors in more than one source file
                  deferredDiagnosticKind = 
DeferredDiagnosticKind.ADDITIONAL_IN_FILES;
                  deferredDiagnosticArg = null;
@@ -159,7 +160,7 @@
                  deferredDiagnosticSource = currentSource;
                  deferredDiagnosticArg = currentSource;
              }  else if (deferredDiagnosticKind == 
DeferredDiagnosticKind.IN_FILE &&
-                        !equal(deferredDiagnosticSource, currentSource)) {
+                        !Objects.equals(deferredDiagnosticSource, 
currentSource)) {
                  // warnings in multiple source files
                  deferredDiagnosticKind = DeferredDiagnosticKind.IN_FILES;
                  deferredDiagnosticArg = null;
@@ -183,13 +184,6 @@
      }

      /**
-     * Check two objects, each possibly null, are either both null or 
are equal.
-     */
-    private static boolean equal(Object o1, Object o2) {
-        return ((o1 == null || o2 == null) ? (o1 == o2) : o1.equals(o2));
-    }
-
-    /**
       * The log to which to report warnings.
       */
      private Log log;



More information about the compiler-dev mailing list