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

XMLGregorianCalendar: out of range values allowed by create/set methods

    XMLWordPrintable

    Details

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

      Description

      Name: erR10175 Date: 12/25/2003


       
        The following methods of the class javax.xml.datatype.XMLGregorianCalendar
        
      public static XMLGregorianCalendar createDateTime(int year, int month, int day,
          int hour, int minute, int second)
      public static XMLGregorianCalendar createDateTime(BigInteger year, int month,
          int day, int hours, int minutes, int seconds, BigDecimal fractionalSecond,
          int timezone)
      public static XMLGregorianCalendar createDateTime(int year, int month, int day,
         int hours, int minutes, int seconds, int milliseconds, int timezone)
      public static XMLGregorianCalendar createDate(int year, int month, int day,
         int timezone)
      public static XMLGregorianCalendar createTime(int hours, int minutes, int seconds,
         int timezone)
      public static XMLGregorianCalendar createTime(int hours, int minutes, int seconds,
         int milliseconds, int timezone)
      public static XMLGregorianCalendar createTime(int hours, int minutes, int seconds,
         BigDecimal fractionalSecond, int timezone)
      public void setTime(int hour, int minute, int second)
      public void setTime(int hour, int minute, int second, int millisecond)
      public void setTime(int hour, int minute, int second, BigDecimal fractional)
      public void setTimezone(int offset)

      do not throw IllegalArgumentException if some of specified parameters violate
      the maximum value space constraints.

      Javadoc of the class reads:

      "All maximum value space constraints listed for the fields in the table above
      are checked by factory methods, setter methods and parse methods of this class.
      IllegalArgumentException is thrown when parameter's value is outside the maximum
      value constraint for the field."

      So, each method call in the test (see below) is expected to throw IllegalArgumentException.

      This bug affects new tests in JCK 1.5 (not integrated yet)
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[CreateDateTime003]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[CreateDateTime005]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[CreateDateTime007]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[CreateDateTime008]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[CreateDate002]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[CreateTime002]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[CreateTime004]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[CreateTime006]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[CreateTime007]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[SetTime002]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[SetTime005]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[SetTime008]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[SetTime009]
          api/javax_xml/datatype/XMLGregorianCalendar/index.html#GetSetCreate[SetTimezone002]

      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;
      import java.math.BigDecimal;

      class test {
          static final BigDecimal _0 = new BigDecimal("0");
          static final BigInteger _1970 = new BigInteger("1970");

          public static void main(String [] args) {
              XMLGregorianCalendar.createDateTime(_1970, 1, 1, 24, 0, 0, _0, 0);
              XMLGregorianCalendar.createDateTime(_1970, 1, 1, 0, 60, 0, _0, 0);
              XMLGregorianCalendar.createDateTime(_1970, 1, 1, 0, 0, 0, new BigDecimal("-0.000001"), 0);
              XMLGregorianCalendar.createDateTime(_1970, 1, 1, 0, 0, 0, new BigDecimal("1.0001"), 0);
              XMLGregorianCalendar.createDateTime(_1970, 1, 1, 0, 0, 0, _0, 840);
              XMLGregorianCalendar.createDateTime(_1970, 1, 1, 0, 0, 0, _0, -840);
              XMLGregorianCalendar.createDateTime(1970, 1, 1, 24, 0, 0);
              XMLGregorianCalendar.createDateTime(1970, 1, 1, 0, 60, 0);
              XMLGregorianCalendar.createDateTime(1970, 1, 1, 24, 0, 0, 0, 0);
              XMLGregorianCalendar.createDateTime(1970, 1, 1, 0, 60, 0, 0, 0);
              XMLGregorianCalendar.createDateTime(1970, 1, 1, 0, 0, 0, 1000, 0);
              XMLGregorianCalendar.createDateTime(1970, 1, 1, 0, 0, 0, -1, 0);
              XMLGregorianCalendar.createDateTime(1970, 1, 1, 0, 0, 0, 0, 840);
              XMLGregorianCalendar.createDateTime(1970, 1, 1, 0, 0, 0, 0, -840);
              XMLGregorianCalendar.createDate(1970, 1, 1, 840);
              XMLGregorianCalendar.createDate(1970, 1, 1, -840);
              XMLGregorianCalendar.createTime(24, 0, 0, 0);
              XMLGregorianCalendar.createTime(0, 60, 0, 0);
              XMLGregorianCalendar.createTime(0, 0, 0, 840);
              XMLGregorianCalendar.createTime(0, 0, 0, -840);
              XMLGregorianCalendar.createTime(24, 0, 0, _0, 0);
              XMLGregorianCalendar.createTime(0, 60, 0, _0, 0);
              XMLGregorianCalendar.createTime(0, 0, 0, new BigDecimal("-0.000001"), 0);
              XMLGregorianCalendar.createTime(0, 0, 0, new BigDecimal("1.0001"), 0);
              XMLGregorianCalendar.createTime(0, 0, 0, _0, 840);
              XMLGregorianCalendar.createTime(0, 0, 0, _0, -840);
              XMLGregorianCalendar.createTime(24, 0, 0, 0, 0);
              XMLGregorianCalendar.createTime(0, 60, 0, 0, 0);
              XMLGregorianCalendar.createTime(0, 0, 0, 1000, 0);
              XMLGregorianCalendar.createTime(0, 0, 0, -1, 0);
              XMLGregorianCalendar.createTime(0, 0, 0, 0, 840);
              XMLGregorianCalendar c = XMLGregorianCalendar.createTime(0, 0, 0, 0, -840);
              c.setTime(24, 0, 0);
              c.setTime(0, 60, 0);
              c.setTime(24, 0, 0, _0);
              c.setTime(0, 60, 0, _0);
              c.setTime(0, 0, 0, new BigDecimal("-0.000001"));
              c.setTime(0, 0, 0, new BigDecimal("1.0001"));
              c.setTime(24, 0, 0, 0);
              c.setTime(0, 60, 0, 0);
              c.setTime(0, 0, 0, -1);
              c.setTime(0, 0, 0, 1000);
              c.setTimezone(840);
              c.setTimezone(-840);

              System.out.println("Failed: IllegalArgumentException is expected");
          }
      }
      ----------------------------------------------------

      ------------------------------------------------ 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: IllegalArgumentException is expected
      ----------------------------------------------------

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

        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: