Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 356189

Summary: Expecting TypeCastException when intialize a date with an invalid string value
Product: z_Archived Reporter: Kathy Carroll <carrollk>
Component: EDTAssignee: Project Inbox <edt.javagen-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jeffdouglas, mheitz
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Additional Variations none

Description Kathy Carroll CLA 2011-08-30 08:35:25 EDT
program drive type BasicProgram {}

    function main()
        creation();
        creationFails();
    end
	
    function creation()
     // This should work
      try
        expecting string = "06/28/1969";
        qDay date = expecting;
        actual string = qDay;
        If (actual == expecting)
            syslib.writeStdOut("MM/DD/YYYY Equal");
        else
            syslib.writeStdout("MM/DD/YYYY Actual/Expecting Different Defect 355782");
            syslib.writeStdout(actual);
            syslib.writeStdout(expecting);
        end
      onException(oops TypeCastException)
           Syslib.writeStdOut(" Can't create date using MM/DD/YYYY");
      end
    end

    function creationFails()
        // this shouldn't work
        try
            expecting string = "19690628";
            qDay date = expecting;
            actual string = qDay;
            If (actual == expecting)
                syslib.writeStdOut("YYYYMMDD Equal");
            else
                syslib.writeStdout("YYYYMMDD Different");
            end
     	onException(oops TypeCastException)
               Syslib.writeStdOut(" Correctly can't create date using YYYYMMDD");
        onException (oops AnyException)
        	if ( oops isa JavaObjectException)
        		objEx JavaObjectException = oops as JavaObjectException;
        		SysLib.writeStdout(" Got an unexpected exception JavaObjectException " + objEX.exceptionType) ; 
        	else
        		SysLib.writeStdout(" Got an unexpected exception") ;
        	end 
        end
    end

end
Comment 1 Matt Heitz CLA 2011-08-30 12:44:36 EDT
Fixed in EString.asString(Calendar).  Needed to move code inside a try block, and make it throw the proper kind of exception from its catch block.
Comment 2 Kathy Carroll CLA 2011-08-31 09:21:53 EDT
verified
Comment 3 Kathy Carroll CLA 2011-10-11 15:09:21 EDT
Fails now with install build 201110110900
Comment 4 Kathy Carroll CLA 2011-10-12 09:30:44 EDT
Created attachment 205033 [details]
Additional Variations

Attached related eunit test variations.  Run RunAllTests_pgms
Comment 5 Jeff Douglas CLA 2011-10-25 09:11:53 EDT
I don't see any error here, other than the expectation in the testcase.

actual timestamp("yyyyMMddHHmmss") = "65*10*31*10*35*55";  

That is a valid date - year = 65, etc

The Calendar object in javagen reports it as valid, that is why there is no exception thrown
Comment 6 Matt Heitz CLA 2011-10-25 09:22:14 EDT
65 is not a valid year.  ETimestamp.asTimestamp(EString,EString) says "Years must be represented with four digits".  If you really want 65 A.D. then the string must start with 0065.
Comment 7 Jeff Douglas CLA 2011-10-25 09:34:01 EDT
The code for this checking came from RBD. Are you saying that this will give an error in RBD?
Comment 8 Jeff Douglas CLA 2011-10-25 09:48:35 EDT
I'm going to update the runtime code for both EDate and ETimestamp to throw an exception if exactly 4 digits are not given for the year. Does that match the spec?
Comment 9 Jeff Douglas CLA 2011-10-25 10:07:13 EDT
Implemented the check for both date and timestamp forcing 4 digits for the year if the year is specified
Comment 10 Matt Heitz CLA 2011-10-25 11:09:05 EDT
Response to comment 7: I don't think it would be an error in RBD, but we're not trying to keep the same behavior in this case.

Response to comments 8 and 9: What you've done does not match the spec for EDate.asDate(EString).  "The year requires a minimum of one digit."  (Why is date flexible but timestamp is strict?  Because dates are much more likely to be entered by a user.)
Comment 11 Jeff Douglas CLA 2011-10-25 11:34:17 EDT
I backed out the code so now date can allow less than 4 digits for the year. This makes timestamp and date inconsistent, but that seems to be what is wanted.
Comment 12 Kathy Carroll CLA 2011-10-27 16:30:31 EDT
Verified 201110271153 & closed.  My original issues have been resolved to my satisfaction.  After reading comment 11, I decided to add a couple of variations to EString009.  I am not getting what I desired.  However, it isn't clear from EString.egl what will be appended to the two digit year. 00? 19? 20?
Comment 13 Matt Heitz CLA 2011-10-28 09:11:20 EDT
(In reply to comment #12)
Any digits not supplied default to zero.  "10" is the year 10, not 1910 or 2010.  No Y2K bugs for us!