castor
  1. castor
  2. CASTOR-1625

DateTimeBase.setCentury() should check for year = 0

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0.3
    • Fix Version/s: 1.0.4
    • Component/s: General
    • Labels:
      None
    • Number of attachments :
      2

      Description

      The method org.exolab.castor.types.DateTimeBase.setCentury() should have the same checking as setYear() to avoid setting century and year to 0:

      else if ( (_year ==0) && (century==0))

      { err = "0000 is not an allowed year"; throw new IllegalArgumentException(err); }

      Otherwise you can do:

      org.exolab.castor.types.Date dob = new org.exolab.castor.types.Date();
      dob.setCentury((short) 1);
      dob.setYear((short) 0);
      dob.setCentury((short) 0); // no exception here

      and if you marshall, you get an "0000-MM-DD" in your XML for date, which is (currently) forbidden (according to http://www.w3.org/TR/xmlschema-2/ chapter 3.2.7).

      If you then unmarshall, you get a (correct) error message for the parser.

      The attached eclipse project showing the error, is compiled with castor 1.0.1, but the problem is also in 1.0.3.

        Activity

        Hide
        Werner Guttmann added a comment -

        Rainer, you wouldn't be able to provide me with a patch and a JUnit test case (to easy my side of things) ?

        Show
        Werner Guttmann added a comment - Rainer, you wouldn't be able to provide me with a patch and a JUnit test case (to easy my side of things) ?
        Hide
        Werner Guttmann added a comment -

        Rainer, please ignore my last comment ...

        Show
        Werner Guttmann added a comment - Rainer, please ignore my last comment ...
        Hide
        Werner Guttmann added a comment -

        Final patch

        Show
        Werner Guttmann added a comment - Final patch

          People

          • Assignee:
            Werner Guttmann
            Reporter:
            Rainer Montag
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 30 minutes
              30m
              Remaining:
              Time Spent - 25 minutes Remaining Estimate - 5 minutes
              5m
              Logged:
              Time Spent - 25 minutes Remaining Estimate - 5 minutes
              25m