Hi Sebb, If I were to do this from scratch I would make each codec object instance-based and constructed from a factory with a "validating" flag. So you'd get a validating or non-validating codec; kind of like an XML parser can validate against a schema or not. This might be too much for a minor release and more in the 2.0 department. In short, I'd rather see a new release with our current batch of changes and punt this for the next release.
Gary On Sun, Mar 26, 2017 at 4:13 PM, sebb <[email protected]> wrote: > Various Codec methods need to encode and decode bytes/Strings. > > Not all byte sequences can be decoded into Strings, and not all > Strings can be encoded into bytes. > > So a decision has to be made as to what to do when an invalid sequence > is detected. > > At present the encoding/decoding is done by the String class > The Javadoc for methods that use a Charset say: > > "This method always replaces malformed-input and unmappable-character > sequences with this charset's default replacement" (byte array or > String depending on direction) > > However the Javadoc for methods that specify the charset name as a String > say: > > "The behavior of this method when this string cannot be encoded in the > given charset is unspecified" > > It looks as though the "unspecified" behaviour is to replace invalid > sequences, but this cannot be guaranteed across all JVMs. > > That can easily be fixed by ensuring that the code only ever uses the > methods that take a Charset. > > However it's not obvious that replacement is the correct policy. > > See for example: > > CODEC-228 URLCodec.decode does not throw DecoderException with invalid > UTF-8 > > It seems to me it would be better to report errors. > > At present, the result of a round-trip encode/decode sequence may not > result in the original input. > That seems wrong for Codec, which IMO should be able to accurately > encode and decode its input. > At present conversions may be silently 'adjusted'. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > -- E-Mail: [email protected] | [email protected] Java Persistence with Hibernate, Second Edition <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459> JUnit in Action, Second Edition <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021> Spring Batch in Action <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951> Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory
