Want to choke up Java's number parsers?

| 0 Comments

Apparently Java's number parsing methods don't like strings that contain null ('\0') characters in them. This was something I noticed when I was writing my file system project for CS450. It creates a formated simulated file system that is nothing but a bunch of null characters and then overwrites them. Wellll when I was writing the code that would read the pointer to the next cluster, there would typically be a number of null characters that had to be read along with the pointer. Needless to say, it wasn't until I filtered out the null characters that it actually worked.

For the newbies out there, here is a simple code example to show what I mean:

public class NullTest
{
    public static void main(String[] args)
    {
        String x = "512\0";
        try
        {
            Integer y = Integer.parseInt(x);
            System.out.println(y);
        }
        catch (NumberFormatException n)
        {
            n.printStackTrace();
            Integer z = Integer.parseInt(x.substring(0, x.indexOf("")));
            System.out.println("Now I get " + z);
        }
    }
}

It's really stupid since null characters are not used by Java for the same thing that they are used for by C. This seems to be a really idiotic bug for them to have not fixed yet. Of course, in their defense, I suppose that very few Java programmers would have occasion to actually use null characters in the first place.

Leave a comment

March 2010

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Recent Entries

A window into the totalitarian mind of the left on freedom of religion
From Digg: Me: I'm not going to hold my breath waiting for the same liberal democrats who shriek about the…
Google's lossy compiler
Google's closure compiler service gets a little too frisky under ADVANCED_OPTIMIZATIONS. Original code: With advanced optimizations enabled, it was able…
The three purposes of the federal income tax law
Businesses will spend about 3.4 billion man-hours and individuals about 1.7 billion hours figuring out their taxes this year.…

Subscribe

Advertisements

OpenID accepted here Learn more about OpenID