I'm continuously amazed at the level of detail that findbugs will go to weed a codebase of bugs. Here's one that I came across today in our codebase:

        
     String[] segments = path.split(file.separator);
File.separator used for regular expression The code here uses File.separator where a regular expression is required. This will fail on Windows platforms, where the File.separator is a backslash, which is interpreted in a regular expression as an escape character.

I don't live in the Windows world, so it would have been months or years before I would have encountered this problem in the wild. Thanks FindBugs team!

Comments:

So, quick question on regexes: from my reading of the javadocs for String.split, it is actually compiling a regex every time it is called. This is no big deal if it is only used once, but can we expect a compiler to notice and reuse the compilation? Or does Pattern cache its compiled forms?

Or is this just a premature optimization question?

Posted by David Buttler on May 20, 2008 at 03:19 PM EDT #

Post a Comment:
Comments are closed for this entry.

This blog copyright 2010 by plamere