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

java.sql.Date::toLocalDate() broken for dates before 1 A.D.

    XMLWordPrintable

Details

    Description

      A DESCRIPTION OF THE PROBLEM :
      toLocalDate() produces a result that is not the inverse of valueOf(LocalDate) for dates before year 1 A.D. In fact years in the B.C. eara are switched to the A.D. eara. So in the executable test case given below, the sqld1 is set to year 2 B.C., but when converted to LocalDate and back again sqld2 becomes year 2 A.D. (Converting year -1 to 2 B.C. is all right considering the Gregorian calendar in java.sql.Date does not have a year 0)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See source code for an executable test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      '0002-01-01 B.C.'.equals('0002-01-01 B.C.'): true, or similar
      '-0001-01-01'.equals('-0001-01-01'): true

      ACTUAL -
      '0002-01-01'.equals('0002-01-01'): false
      '-0001-01-01'.equals('0002-01-01'): false


      ---------- BEGIN SOURCE ----------
      LocalDate ld = LocalDate.of(-1, Month.JANUARY, 1);
      java.sql.Date sqld1 = java.sql.Date.valueOf(ld);
      LocalDate ld1 = sqld1.toLocalDate();
      java.sql.Date sqld2 = java.sql.Date.valueOf(ld1);
      System.out.printf("'%s'.equals('%s'): %b", sqld2, sqld1, sqld2.equals(sqld1));
      System.out.println();
      System.out.printf("'%s'.equals('%s'): %b", ld, ld1, ld.equals(ld1));

      ---------- END SOURCE ----------

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              lancea Lance Andersen
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: