Re: How would I rewrite this to satisfy the code checker?
On Nov 4, 2:21 pm, Lew <l...@lewscanon.com> wrote:
laredotornado wrote:
I'm using Java 1.5, Eclipse Galileo on Mac 10.5.6 and the code
checking plug-in (PMD) is complaining about the below block ...
BufferedReader read=
er = new BufferedReader(new InputStreamReader
(fileStream));
Hey, lighten up on the indentation!
Use a maximum of four spaces per indent level and don't use TAB
characters for Usenet code posts.
StringBuilder strin=
gBuf = new StringBuilder();
Your variable name choice is slightly misleading.
String line = nul=
l;
le ((line = reader.readLine()) != null) {
stringBuf.append(line + "\n");
}
saying, "Avoid assignments in operands". How would I rewrite the
while loop to make this error go away but achieve the same
functionality?
It's not an error, it's a warning and not even a standard warning for
Java. It's a perfectly legal construct. However, it does elevate th=
e
scope of the variable 'line' beyond where it should be. Also, the
assignment of 'null' to it is superfluous. So really your "checker"
is giving you good advice.
You could use a 'for' loop.
for ( String line = reader.readLine(); line != null; line =
reader.readLine() )
{
...
}
Does FindBugs work on the Mac?
--
Lew
Sweet! Works like a dream. 5 stars.
I don't know if FindBugs works on a Mac but there is a plug-in for
Eclipse and since Eclipse is cross-platform, I assume so, but haven't
tried FindBugs yet.
Thanks, -