Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8273644

equals method does not implemented correcty with values

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu 20.04

      A DESCRIPTION OF THE PROBLEM :
      the phrase `Long.valueOf(0).equals(0)` always returns false, similar issues in Integer,Double,Float implementation.
      In the Implementation, the first line of code in `equals` function is an Exact type check,
      this issue is become critical, specially, when other API wants to generate a collection of numbers, and for instance, they decide to create either List<Integer> or List<Long> according to data-range dynamically (such as Mongo library which store/retrieve data in `Document` format, load some data as Integer, Long or Double according to their value), in this case, contains function would not always work correct.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      System.out.println(Long.valueOf(0).equals(0));

      ACTUAL -
      false

      ---------- BEGIN SOURCE ----------
      public class Main {
          public static void main(String[] args) {
              System.out.println(Long.valueOf(0).equals(0));
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      no explicit way to repair, and the neat method is to cast the list to desired type (re-new the List) or scan the list and cast an compare one-by-one, both methods are low performance way

      FREQUENCY : always


      Attachments

        Activity

          People

            tongwan Andrew Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: