<i18n dev> java.util.Fomatter precision and surrogate pairs

Naoto Sato naoto.sato at oracle.com
Sun Feb 14 18:00:02 UTC 2021

Hi Jason,

On 2/13/21 4:09 PM, Jason Mehrens wrote:
> Hi Naoto,
> Sorry for the off thread reply.  I didn't have the mail replies setup on the list and I seem to be unable to add a in-reply-to header via web email.
>> Although the error message may be confusing, 'c' conversion cannot be
>> used for a String argument (like in your example). It simply converts
>> numeric value into a single character, thus no need for output
>> "precision." I am not the designer of the class, so might be wrong.
> Yes I totally missed that.  I dug up the relevant source:
> https://urldefense.com/v3/__https://github.com/openjdk/jdk/blob/350303d4f0c71f77fa784a92d13522a380e3b2fe/src/java.base/share/classes/java/util/Formatter.java*L3006__;Iw!!GqivPVa7Brio!JREncVIBVl3dT2Md_OG5ooK5zYJ9KbJCW8B4Y_9ZyRSXHRlZxda9ZBCpwC9pyV4u$
> https://urldefense.com/v3/__https://github.com/openjdk/jdk/blob/c709e1cbf030e7129fa34815b150097ba6f6840c/test/jdk/java/util/Formatter/Basic-X.java.template*L432__;Iw!!GqivPVa7Brio!JREncVIBVl3dT2Md_OG5ooK5zYJ9KbJCW8B4Y_9ZyRSXHRlZxda9ZBCpwERFw-xy$
> So this code doesn't deal with CharSequence and therefore the precision is implicitly one.  With the exception if null getting converted to 4 chars.
> Is it worth me filing an RFE to allow 'c' to accept a CharSequence and allow precision to be set?

Again, 'c' is for a single character, so I don't think taking 
CharSequence as an argument is the right choice. Rather, I would fix the 
current spec/behavior of 's', which bisects a supplementary character at 
the end. To me, it is just supplementary characters are not handled 
correctly in 's' conversion.


More information about the i18n-dev mailing list