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

XMLGregorianCalendar.getEonAndYear() returns incorrect values

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b35
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description



      Name: erR10175 Date: 12/26/2003


       
        The following method of the class javax.xml.datatype.XMLGregorianCalendar
        
      public BigInteger getEonAndYear()

      returns wrong values for years outside the range from -10^9 to 10^9.

      According to the javadoc of the class, the field Year is capable to store
      arbitrary big integer years. So, it should be possible to set and get Year to
      values greater than 10^9 and less than -10^9. The method getEonAndYear()
      is expected to return exactly what is set by method setYear(BigInteger year)
      or by createDateTime(BigInteger year, ...).

      This bug affects new tests in JCK 1.5 (not integrated yet)
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[CreateDateTime002]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[GetEon001]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[GetEonAndYear001]

      The bug is found in jdk1.5.0/beta/b32.

      To reproduce the bug compile and run the following code as shown
      in the log below.
      ------------------------------------------ test.java
      import javax.xml.datatype.XMLGregorianCalendar;
      import java.math.BigInteger;

      class test {
          static final BigInteger BILLION = new BigInteger("1000000000");
          static final BigInteger mBILLIONo = new BigInteger("-1000000001");
          public static void main(String [] args) {
              XMLGregorianCalendar c
                  = XMLGregorianCalendar.createDateTime(BILLION, 1, 1, 0, 0, 0, null, 0);
              BigInteger year = c.getEonAndYear();
              if (!BILLION.equals(year)) {
                  System.out.println("Failed: returned " + year
                                   + ", expected " + BILLION);
              } else {
                  System.out.println("OK: returned " + year);
              }
              c.setYear(mBILLIONo);
              year = c.getEonAndYear();
              if (!mBILLIONo.equals(year)) {
                  System.out.println("Failed: returned " + year
                                   + ", expected " + mBILLIONo);
              } else {
                  System.out.println("OK: returned " + year);
              }
          }
      }
      ----------------------------------------------------

      ------------------------------------------------ log
      $javac test.java && java -cp . -showversion test
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b32, mixed mode)

      Failed: returned 1, expected 1000000000
      Failed: returned -2, expected -1000000001
      ----------------------------------------------------

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            jfialli Joe Fialli
            Reporter:
            reysunw Rey Rey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: