ICU-12739 Fixed a compiler warning and issues reported by Find Bugs.
authorYoshito Umaoka <y.umaoka@gmail.com>
Tue, 20 Sep 2016 23:02:20 +0000 (23:02 +0000)
committerYoshito Umaoka <y.umaoka@gmail.com>
Tue, 20 Sep 2016 23:02:20 +0000 (23:02 +0000)
X-SVN-Rev: 39302

icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetMBCS.java
icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationFastLatin.java
icu4j/main/classes/core/src/com/ibm/icu/impl/TimeZoneNamesImpl.java
icu4j/main/classes/core/src/com/ibm/icu/text/DecimalFormat.java
icu4j/main/classes/core/src/com/ibm/icu/text/PluralRules.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/normalizer/BasicTest.java

index b6b92c489097152be8b8c3e6af85facd23727849..d5fc2657779d4bda0c3519815a0dc0adbf37515e 100644 (file)
@@ -511,7 +511,6 @@ class CharsetMBCS extends CharsetICU {
         int p;
         int c;
         int i, st3;
-        long temp;
 
         table = mbcsTable.fromUnicodeTable;
         int[] tableInts = mbcsTable.fromUnicodeTableInts;
@@ -579,10 +578,8 @@ class CharsetMBCS extends CharsetICU {
             }
 
             // Set the roundtrip flag.
-            // FindBugs complains about "possible bad parsing of shift operation"
-            // but this is as intended.
-            temp = (1L<<(16+(c&0xf)));
-            tableInts[stage2] |= temp;
+            int shift = 16 + (c & 0x0F);
+            tableInts[stage2] |= (1L << shift);
         }
         return true;
      }
index f4b0d198e39868e3ce2a8d3a9e0d70798cb92652..1c5033e30675344afb6837c5413ad78a7553b8a4 100644 (file)
@@ -204,10 +204,10 @@ public final class CollationFastLatin /* all static */ {
         char[] header = data.fastLatinTableHeader;
         if(header == null) { return -1; }
         assert((header[0] >> 8) == VERSION);
-        assert(primaries.length == LATIN_LIMIT);
-        // FindBugs complains that primaries.length == LATIN_LIMIT is known after the assert,
-        // but we keep this here for when assertions are disabled.
-        if(primaries.length != LATIN_LIMIT) { return -1; }
+        if(primaries.length != LATIN_LIMIT) {
+            assert false;
+            return -1;
+        }
 
         int miniVarTop;
         if((settings.options & CollationSettings.ALTERNATE_MASK) == 0) {
index 2a291463a64059187453915dab35092870712fff..3d2900fcabbe2816399280f7bad495c91d9c6454 100644 (file)
@@ -668,6 +668,9 @@ public class TimeZoneNamesImpl extends TimeZoneNames {
             for (int i = 0; i < ZNames.NUM_NAME_TYPES; ++i) {
                 String name = names[i];
                 if (name != null) {
+                    // TODO Findbugs: Comparison of String objects using == or !=
+                    // Review the logic and modify below if necessary. See ticket #12746.
+
                     // FindBugs complains about == but
                     // we do want to check for the NO_NAME reference, not its contents!
                     if (name == NO_NAME) {
index cdc719f98f7203c11324f6c61acc9797fbce3ea9..23fc81696abbe6dc1f28f93e6b86c35511d30a30 100644 (file)
@@ -2597,7 +2597,7 @@ public class DecimalFormat extends NumberFormat {
 
                     // If we're only parsing integers, or if we ALREADY saw the decimal,
                     // then don't parse this one.
-                    if (isParseIntegerOnly() || sawDecimal) {
+                    if (isParseIntegerOnly()) {
                         break;
                     }
 
index 3f1768c0166d6fd6196f0667db12aacfc06591dc..970f7ca04aaf22bcae5cbc4e16c7ffa832fa44e9 100644 (file)
@@ -54,7 +54,7 @@ import com.ibm.icu.util.ULocale;
  * <p>
  * Examples:
  * </p>
- * 
+ *
  * <pre>
  * &quot;one: n is 1; few: n in 2..4&quot;
  * </pre>
@@ -64,7 +64,7 @@ import com.ibm.icu.util.ULocale;
  * between 2 and 4 inclusive - and be an integer - for this condition to pass. All other numbers are assigned the
  * keyword "other" by the default rule.
  * </p>
- * 
+ *
  * <pre>
  * &quot;zero: n is 0; one: n is 1; zero: n mod 100 in 1..19&quot;
  * </pre>
@@ -73,7 +73,7 @@ import com.ibm.icu.util.ULocale;
  * keyword whose condition passes is the one returned. Also notes that a modulus is applied to n in the last rule. Thus
  * its condition holds for 119, 219, 319...
  * </p>
- * 
+ *
  * <pre>
  * &quot;one: n is 1; few: n mod 10 in 2..4 and n mod 100 not in 12..14&quot;
  * </pre>
@@ -164,7 +164,7 @@ import com.ibm.icu.util.ULocale;
  * includes all values. Using 'within' with a range_list consisting entirely of values is the same as using 'in' (it's
  * not an error).
  * </p>
- * 
+ *
  * @stable ICU 3.8
  */
 public class PluralRules implements Serializable {
@@ -192,7 +192,7 @@ public class PluralRules implements Serializable {
 
     /**
      * Provides a factory for returning plural rules
-     * 
+     *
      * @internal
      * @deprecated This API is ICU internal only.
      */
@@ -209,11 +209,11 @@ public class PluralRules implements Serializable {
 
         /**
          * Provides access to the predefined <code>PluralRules</code> for a given locale and the plural type.
-         * 
+         *
          * <p>
          * ICU defines plural rules for many locales based on CLDR <i>Language Plural Rules</i>. For these predefined
          * rules, see CLDR page at http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
-         * 
+         *
          * @param locale
          *            The locale for which a <code>PluralRules</code> object is returned.
          * @param type
@@ -241,7 +241,7 @@ public class PluralRules implements Serializable {
 
         /**
          * Returns the locales for which there is plurals data.
-         * 
+         *
          * @internal
          * @deprecated This API is ICU internal only.
          */
@@ -254,7 +254,7 @@ public class PluralRules implements Serializable {
          * All locales with the same functionally equivalent locale have plural rules that behave the same. This is not
          * exaustive; there may be other locales whose plural rules behave the same that do not have the same equivalent
          * locale.
-         * 
+         *
          * @param locale
          *            the locale to check
          * @param isAvailable
@@ -355,21 +355,24 @@ public class PluralRules implements Serializable {
     private static final Constraint NO_CONSTRAINT = new Constraint() {
         private static final long serialVersionUID = 9163464945387899416L;
 
+        @Override
         public boolean isFulfilled(FixedDecimal n) {
             return true;
         }
 
+        @Override
         public boolean isLimited(SampleType sampleType) {
             return false;
         }
 
+        @Override
         public String toString() {
             return "";
         }
     };
 
     /**
-     * 
+     *
      */
     private static final Rule DEFAULT_RULE = new Rule("other", NO_CONSTRAINT, null, null);
 
@@ -574,12 +577,12 @@ public class PluralRules implements Serializable {
             source = isNegative ? -n : n;
             visibleDecimalDigitCount = v;
             decimalDigits = f;
-            integerValue = n > MAX 
-                    ? MAX 
+            integerValue = n > MAX
+                    ? MAX
                             : (long)n;
             hasIntegerValue = source == integerValue;
             // check values. TODO make into unit test.
-            //            
+            //
             //            long visiblePower = (int) Math.pow(10, v);
             //            if (fractionalDigits > visiblePower) {
             //                throw new IllegalArgumentException();
@@ -654,7 +657,7 @@ public class PluralRules implements Serializable {
          * Returns 0 for infinities and nans.
          * @internal
          * @deprecated This API is ICU internal only.
-         * 
+         *
          */
         @Deprecated
         public static int decimals(double n) {
@@ -693,7 +696,7 @@ public class PluralRules implements Serializable {
                     if (buf.charAt(i) != '0') {
                         break;
                     }
-                    --numFractionDigits; 
+                    --numFractionDigits;
                 }
                 return numFractionDigits;
             }
@@ -749,6 +752,7 @@ public class PluralRules implements Serializable {
          * @internal
          * @deprecated This API is ICU internal only.
          */
+        @Override
         @Deprecated
         public int compareTo(FixedDecimal other) {
             if (integerValue != other.integerValue) {
@@ -1007,7 +1011,7 @@ public class PluralRules implements Serializable {
                 }
                 String[] rangeParts = TILDE_SEPARATED.split(range);
                 switch (rangeParts.length) {
-                case 1: 
+                case 1:
                     FixedDecimal sample = new FixedDecimal(rangeParts[0]);
                     checkDecimal(sampleType2, sample);
                     samples2.add(new FixedDecimalRange(sample, sample));
@@ -1027,7 +1031,7 @@ public class PluralRules implements Serializable {
 
         private static void checkDecimal(SampleType sampleType2, FixedDecimal sample) {
             if ((sampleType2 == SampleType.INTEGER) != (sample.getVisibleDecimalDigitCount() == 0)) {
-                throw new IllegalArgumentException("Ill-formed number range: " + sample);    
+                throw new IllegalArgumentException("Ill-formed number range: " + sample);
             }
         }
 
@@ -1255,7 +1259,7 @@ public class PluralRules implements Serializable {
                                     if (!t.equals(",")) { // adjacent number: 1 2
                                         // no separator, fail
                                         throw unexpected(t, condition);
-                                    }                                
+                                    }
                                 }
                             } else if (!t.equals(",")) { // adjacent number: 1 2
                                 // no separator, fail
@@ -1373,7 +1377,7 @@ public class PluralRules implements Serializable {
         FixedDecimalSamples integerSamples = null, decimalSamples = null;
         switch (constraintOrSamples.length) {
         case 1: break;
-        case 2: 
+        case 2:
             integerSamples = FixedDecimalSamples.parse(constraintOrSamples[1]);
             if (integerSamples.sampleType == SampleType.DECIMAL) {
                 decimalSamples = integerSamples;
@@ -1387,7 +1391,7 @@ public class PluralRules implements Serializable {
                 throw new IllegalArgumentException("Must have @integer then @decimal in " + description);
             }
             break;
-        default: 
+        default:
             throw new IllegalArgumentException("Too many samples in " + description);
         }
         if (sampleFailure) {
@@ -1419,7 +1423,7 @@ public class PluralRules implements Serializable {
             throws ParseException {
         RuleList result = new RuleList();
         // remove trailing ;
-        if (description.endsWith(";")) { 
+        if (description.endsWith(";")) {
             description = description.substring(0,description.length()-1);
         }
         String[] rules = SEMI_SEPARATED.split(description);
@@ -1458,6 +1462,7 @@ public class PluralRules implements Serializable {
             this.operand = operand;
         }
 
+        @Override
         public boolean isFulfilled(FixedDecimal number) {
             double n = number.get(operand);
             if ((integersOnly && (n - (long)n) != 0.0
@@ -1477,27 +1482,29 @@ public class PluralRules implements Serializable {
             return inRange == test;
         }
 
+        @Override
         public boolean isLimited(SampleType sampleType) {
             boolean valueIsZero = lowerBound == upperBound && lowerBound == 0d;
-            boolean hasDecimals = 
+            boolean hasDecimals =
                     (operand == Operand.v || operand == Operand.w || operand == Operand.f || operand == Operand.t)
                     && inRange != valueIsZero; // either NOT f = zero or f = non-zero
             switch (sampleType) {
-            case INTEGER: 
+            case INTEGER:
                 return hasDecimals // will be empty
                         || (operand == Operand.n || operand == Operand.i || operand == Operand.j)
-                        && mod == 0 
+                        && mod == 0
                         && inRange;
 
             case DECIMAL:
                 return  (!hasDecimals || operand == Operand.n || operand == Operand.j)
                         && (integersOnly || lowerBound == upperBound)
-                        && mod == 0 
+                        && mod == 0
                         && inRange;
             }
             return false;
         }
 
+        @Override
         public String toString() {
             StringBuilder result = new StringBuilder();
             result.append(operand);
@@ -1508,7 +1515,7 @@ public class PluralRules implements Serializable {
             result.append(
                     !isList ? (inRange ? " = " : " != ")
                             : integersOnly ? (inRange ? " = " : " != ")
-                                    : (inRange ? " within " : " not within ") 
+                                    : (inRange ? " within " : " not within ")
                     );
             if (range_list != null) {
                 for (int i = 0; i < range_list.length; i += 2) {
@@ -1558,18 +1565,21 @@ public class PluralRules implements Serializable {
             super(a, b);
         }
 
+        @Override
         public boolean isFulfilled(FixedDecimal n) {
-            return a.isFulfilled(n) 
+            return a.isFulfilled(n)
                     && b.isFulfilled(n);
         }
 
+        @Override
         public boolean isLimited(SampleType sampleType) {
             // we ignore the case where both a and b are unlimited but no values
             // satisfy both-- we still consider this 'unlimited'
-            return a.isLimited(sampleType) 
+            return a.isLimited(sampleType)
                     || b.isLimited(sampleType);
         }
 
+        @Override
         public String toString() {
             return a.toString() + " and " + b.toString();
         }
@@ -1583,16 +1593,19 @@ public class PluralRules implements Serializable {
             super(a, b);
         }
 
+        @Override
         public boolean isFulfilled(FixedDecimal n) {
-            return a.isFulfilled(n) 
+            return a.isFulfilled(n)
                     || b.isFulfilled(n);
         }
 
+        @Override
         public boolean isLimited(SampleType sampleType) {
-            return a.isLimited(sampleType) 
+            return a.isLimited(sampleType)
                     && b.isLimited(sampleType);
         }
 
+        @Override
         public String toString() {
             return a.toString() + " or " + b.toString();
         }
@@ -1603,6 +1616,8 @@ public class PluralRules implements Serializable {
      * Provides 'and' and 'or' to combine constraints.  Immutable.
      */
     private static class Rule implements Serializable {
+        // TODO - Findbugs: Class com.ibm.icu.text.PluralRules$Rule defines non-transient
+        // non-serializable instance field integerSamples. See ticket#10494.
         private static final long serialVersionUID = 1;
         private final String keyword;
         private final Constraint constraint;
@@ -1638,8 +1653,9 @@ public class PluralRules implements Serializable {
             return constraint.isLimited(sampleType);
         }
 
+        @Override
         public String toString() {
-            return keyword + ": " + constraint.toString() 
+            return keyword + ": " + constraint.toString()
                     + (integerSamples == null ? "" : " " + integerSamples.toString())
                     + (decimalSamples == null ? "" : " " + decimalSamples.toString());
         }
@@ -1743,6 +1759,7 @@ public class PluralRules implements Serializable {
             return result;
         }
 
+        @Override
         public String toString() {
             StringBuilder builder = new StringBuilder();
             for (Rule rule : rules) {
@@ -2017,7 +2034,7 @@ public class PluralRules implements Serializable {
      * @param type the type of samples requested, INTEGER or DECIMAL
      * @return the values that trigger this keyword, or null.  The returned collection
      * is immutable. It will be empty if the keyword is not defined.
-     * 
+     *
      * @internal
      * @deprecated This API is ICU internal only.
      */
@@ -2164,6 +2181,7 @@ public class PluralRules implements Serializable {
      * {@inheritDoc}
      * @stable ICU 3.8
      */
+    @Override
     public String toString() {
         return rules.toString();
     }
@@ -2172,6 +2190,7 @@ public class PluralRules implements Serializable {
      * {@inheritDoc}
      * @stable ICU 3.8
      */
+    @Override
     public boolean equals(Object rhs) {
         return rhs instanceof PluralRules && equals((PluralRules)rhs);
     }
@@ -2189,42 +2208,42 @@ public class PluralRules implements Serializable {
 
     /**
      * Status of the keyword for the rules, given a set of explicit values.
-     * 
+     *
      * @draft ICU 50
      * @provisional This API might change or be removed in a future release.
      */
     public enum KeywordStatus {
         /**
          * The keyword is not valid for the rules.
-         * 
+         *
          * @draft ICU 50
          * @provisional This API might change or be removed in a future release.
          */
         INVALID,
         /**
          * The keyword is valid, but unused (it is covered by the explicit values, OR has no values for the given {@link SampleType}).
-         * 
+         *
          * @draft ICU 50
          * @provisional This API might change or be removed in a future release.
          */
         SUPPRESSED,
         /**
          * The keyword is valid, used, and has a single possible value (before considering explicit values).
-         * 
+         *
          * @draft ICU 50
          * @provisional This API might change or be removed in a future release.
          */
         UNIQUE,
         /**
          * The keyword is valid, used, not unique, and has a finite set of values.
-         * 
+         *
          * @draft ICU 50
          * @provisional This API might change or be removed in a future release.
          */
         BOUNDED,
         /**
          * The keyword is valid but not bounded; there indefinitely many matching values.
-         * 
+         *
          * @draft ICU 50
          * @provisional This API might change or be removed in a future release.
          */
@@ -2233,7 +2252,7 @@ public class PluralRules implements Serializable {
 
     /**
      * Find the status for the keyword, given a certain set of explicit values.
-     * 
+     *
      * @param keyword
      *            the particular keyword (call rules.getKeywords() to get the valid ones)
      * @param offset
@@ -2253,7 +2272,7 @@ public class PluralRules implements Serializable {
     }
     /**
      * Find the status for the keyword, given a certain set of explicit values.
-     * 
+     *
      * @param keyword
      *            the particular keyword (call rules.getKeywords() to get the valid ones)
      * @param offset
index 41454b836134f1b780b64a72ccad233d0844c161..d88f3caa34695ee41c4a7e8ee72047ef627156d9 100644 (file)
@@ -1615,7 +1615,7 @@ public class BasicTest extends TestFmwk {
 
         // Concatenates 're' with '\u0301sum\u00e9 is HERE' and places the result at
         // position 3 of string 'My resume is here'.
-        int len = Normalizer.concatenate(left.toCharArray(), 0, 2, right.toCharArray(), 2, 15,
+        Normalizer.concatenate(left.toCharArray(), 0, 2, right.toCharArray(), 2, 15,
                                          destination, 3, 17, mode, 0);
         if(!String.valueOf(destination).equals(expect)) {
             errln("error in Normalizer.concatenate(), cases2[] failed"
@@ -1625,12 +1625,12 @@ public class BasicTest extends TestFmwk {
 
         // Error case when result of concatenation won't fit into destination array.
         try {
-            len = Normalizer.concatenate(left.toCharArray(), 0, 2, right.toCharArray(), 2, 15,
+            Normalizer.concatenate(left.toCharArray(), 0, 2, right.toCharArray(), 2, 15,
                                          destination, 3, 16, mode, 0);
         } catch (IndexOutOfBoundsException e) {
             assertTrue("Normalizer.concatenate() failed", e.getMessage().equals("14"));
             return;
-       }
+        }
         fail("Normalizer.concatenate() tested for failure but passed");
     }
 
@@ -1734,7 +1734,7 @@ public class BasicTest extends TestFmwk {
     private int ref_norm_compare(String s1, String s2, int options) {
         String t1, t2,r1,r2;
 
-        int normOptions=(int)(options>>Normalizer.COMPARE_NORM_OPTIONS_SHIFT);
+        int normOptions=options>>Normalizer.COMPARE_NORM_OPTIONS_SHIFT;
 
         if((options&Normalizer.COMPARE_IGNORE_CASE)!=0) {
             // NFD(toCasefold(NFD(X))) = NFD(toCasefold(NFD(Y)))
@@ -1763,7 +1763,7 @@ public class BasicTest extends TestFmwk {
 
     // test wrapper for Normalizer::compare, sets UNORM_INPUT_IS_FCD appropriately
     private int norm_compare(String s1, String s2, int options) {
-        int normOptions=(int)(options>>Normalizer.COMPARE_NORM_OPTIONS_SHIFT);
+        int normOptions=options>>Normalizer.COMPARE_NORM_OPTIONS_SHIFT;
 
         if( Normalizer.YES==Normalizer.quickCheck(s1,Normalizer.FCD,normOptions) &&
             Normalizer.YES==Normalizer.quickCheck(s2,Normalizer.FCD,normOptions)) {
@@ -2428,7 +2428,7 @@ public class BasicTest extends TestFmwk {
         };
         StringBuilder s, pattern;
 
-        // build NF*Skippable sets from runtime data 
+        // build NF*Skippable sets from runtime data
         skipSets[D].applyPattern("[:NFD_Inert:]");
         skipSets[C].applyPattern("[:NFC_Inert:]");
         skipSets[KD].applyPattern("[:NFKD_Inert:]");
@@ -2867,17 +2867,28 @@ public class BasicTest extends TestFmwk {
     public class TestNormalizer2 extends Normalizer2 {
 
         public TestNormalizer2() {}
+        @Override
         public StringBuilder normalize(CharSequence src, StringBuilder dest) { return null; }
+        @Override
         public Appendable normalize(CharSequence src, Appendable dest) { return null; }
+        @Override
         public StringBuilder normalizeSecondAndAppend(
             StringBuilder first, CharSequence second) { return null; }
+        @Override
         public StringBuilder append(StringBuilder first, CharSequence second) { return null; }
+        @Override
         public String getDecomposition(int c) { return null; }
+        @Override
         public boolean isNormalized(CharSequence s) { return false; }
+        @Override
         public Normalizer.QuickCheckResult quickCheck(CharSequence s) { return null; }
+        @Override
         public int spanQuickCheckYes(CharSequence s) { return 0; }
+        @Override
         public boolean hasBoundaryBefore(int c) { return false; }
+        @Override
         public boolean hasBoundaryAfter(int c) { return false; }
+        @Override
         public boolean isInert(int c) { return false; }
     }