Note that there are some explanatory texts on larger screens.

plurals
  1. POFind Bugs - Not finding bugs
    text
    copied!<p>I have recently set up find bugs in eclipse to see what reports it generates. Ive set all the settings to be as sensitive as possible. If i create a small application that writes to a file and do not close the stream it picks it up which is all good.</p> <p>However, using a project that has been written where we no there are a couple of bugs, especially in the output, we get no errors at all (in terms of find bugs)</p> <p>I was wondering if anyone could run this through their version and report whether I may have find bugs set up incorrectly or whether in fact it could find no bugs?</p> <pre><code>import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class SpellUtil { private final static String teenSpelling[] = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"}; private final static String centSpelling[] = {"Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}; private final static String suffixSpelling[] = { "", // Dummy! no level 0 (added for nicer indexing in code) "", // Nothing for level 1 " Thousand, ", " Million, ", " Billion, ", " Trillion, ", " Quadrillion, ", " Quintillion, "}; public static String spell(int number) { int rem, placeIndicator = 1; boolean isNegative = false; List&lt;String&gt; spelling = new ArrayList&lt;String&gt;(); if (number &lt; 0) { isNegative = true; number = Math.abs(number); } while (number &gt; 0) { rem = number % 1000; number = number / 1000; spelling.add(suffixSpelling[placeIndicator]); try { spelling.add(spellBelow1000(rem)); } catch (SpellingException e) { System.out.println(e.getMessage()); } placeIndicator++; } StringBuilder sb = new StringBuilder(); if (isNegative) sb.append("Minus "); for (int i = spelling.size() - 1; i &gt;= 0; i--) { sb.append(spelling.get(i)); } return sb.toString(); } private static String spellBelow1000(int number) throws SpellingException { if (number &lt; 0 || number &gt;= 1000) throw new SpellingException("Expecting a number between 0 and 999: " + number); if (number &lt; 20) { // if number is a teen, // find it in teen table and return its equivalent text (word). return teenSpelling[number]; } else if (number &lt; 100) { // otherwise, if it is a cent, // find the most (div) and least (rem) significant digits (MSD/LSD) int div = (int) number / 10; int rem = (int) number % 10; if (rem == 0) { // if LSD is zero, return the cent key word directly (like // fifty). return centSpelling[div-2]; } else { // otherwise, return the text as cent-teen (like fifty-one) return centSpelling[div-2] + "-" + teenSpelling[rem]; } } else { // otherwise, it is a mil; // find it's MSD and remaining cent. int div = number / 100; int rem = (int) number % 100; // TODO will findbugs detect unnecessary (int)? // Prepare the mil prefix: String milText = teenSpelling[div] + " Hundred"; // decide whether to append the cent tail or not. if (rem == 0) { // if it does have a non-zero cent, that's it. // return the mil prefix, for example three hundred: return milText; } else { // otherwise, spell the cent and append it to mil prefix. // (now, rem is a cent). // For example, three Hundred and Sixty-Four: return milText + " and " + spellBelow1000(rem); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload