[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


From: Chris Lansdown
Subject: java.swing.text.NumberFormatter
Date: Thu, 22 Dec 2005 12:34:57 -0500
User-agent: Mutt/1.5.9i


NumberFormatter's stringToValue function currently checks to see if the
valueClass is not null, and if so, converts its value to that.

The problem is that valueClass gets set in
java.swing.text.DefaultFormatter's constructor sets valueClass to be
Object.class, so the lines:

      if (valueClass != null)
          o = super.stringToValue(o.toString());

have the effect of always setting the returned value to a String, even
though NumberFormatter properly converts the thing to a number first.

Two alternative fixes would be to get rid of the always setting valueClass
in DefaultFormatter's constructor (I have no idea what the implications of
this are), and changing the condition to:

if(valueClass != null && valueClass != Object.class)

Since there's no sense in trying to cast something up to an object anyhow.

Alternatively, maybe the constructor of NumberFormat should set the
valueClass to Number?

Chris Lansdown

"Let us endeavor so to live that when we come to die even the undertaker 
will be sorry."  -- Mark Twain, "Pudd'nhead Wilson's Calendar"
========== Evil Overlord Quote of the Day ( =========
214. If a malignant being demands a sacrificial victim have a particular
quality, I will check to make sure said victim has this quality
immediately before the sacrifice and not rely on earlier results.
(Especially if the quality is virginity and the victim is the hero's

reply via email to

[Prev in Thread] Current Thread [Next in Thread]