[threeten-dev] javax.time.format.DateTimeFormattter#toFormat(Class<?> parseType) API specification

Stephen Colebourne scolebourne at joda.org
Wed Dec 5 08:25:30 PST 2012


On 5 December 2012 04:02,  <yoshito_umaoka at us.ibm.com> wrote:
> I have some comments and questions about public Format
> DateTimeFormatter#toFormat(Class<?> parseType) API specification [
> http://threeten.sourceforge.net/apidocs-2012-10-25/javax/time/format/DateTimeFormatter.html#toFormat%28java.lang.Class%29
> ].
>
> The specification says:
>
> "Returns this formatter as a java.text.Format instance that will parse to
> the specified type."
>
> I think the implementation is likely supporting only some known object
> types and the method would throw IllegalArgumentException or something if
> the given parseType is not supported. I think the spec should clarify what
> kind of argument is likely supported here and type of exception (or
> returning null?) when unsupported type is specified.

It takes a class that can be resolved to a date, generally a subclass
of DateTimeAccessor.

> Also, it says:
>
> "The format will throw IndexOutOfBoundsException in line with those thrown
> by the print and parse methods."
>
> This description does not sound right. My understanding is "The format" is
> an instance of java.text.Format subclass. Format defines two parse methods
> - 1) Object parseObject(String) and 2) abstract Object parseObject(String,
> ParsePosition) - I do not know what "print" method in the spec actually
> means (Format defines "format" methods, not "print"). In addition to
> these, it's difficult to understand why IndexOutOfBoundsException might be
> thrown by "The format". By the contract of java.textFormat, format method
> should not throw any exception and parseObject should throw
> java.text.ParseException on parse failure. So I have no idea where this
> IndexOutOfBoundsException come from.

The contract of Format is incomplete. Passing a ParsePosition with a
negative number to a SimpleDateFormat will throw a
StringIndexOOBException. DateTimeFormatter is allowed to thow
IOOBException from parseToBuilder.

I'm making various updates to try and clarify the behavior.

thanks
Stephen


More information about the threeten-dev mailing list