Fix various FindBugs warnings.

Only the ChunkHandler and ZoneInfo ones were real bugs. The former is only
called with one input value that doesn't exercise the bug, and the latter
would cause us to think that a time zone that stopped using daylight time
before 1970 was still using daylight time (which would defeat various
optimizations, but should otherwise be harmless).

The other stuff is trivia not worth individual changes.

Change-Id: Ib0752560cd16edc6538d1fc2b234451a66d48171
diff --git a/dalvik/src/main/java/org/apache/harmony/dalvik/ddmc/ChunkHandler.java b/dalvik/src/main/java/org/apache/harmony/dalvik/ddmc/ChunkHandler.java
index 5ca3b2a..5d0073b 100644
--- a/dalvik/src/main/java/org/apache/harmony/dalvik/ddmc/ChunkHandler.java
+++ b/dalvik/src/main/java/org/apache/harmony/dalvik/ddmc/ChunkHandler.java
@@ -108,19 +108,15 @@
     /**
      * Convert a 4-character string to a 32-bit type.
      */
-    public static int type(String typeName)
-    {
-        int val = 0;
-
-        if (typeName.length() != 4)
-            throw new RuntimeException();
-
-        for (int i = 0; i < 4; i++) {
-            val <<= 8;
-            val |= (byte) typeName.charAt(i);
+    public static int type(String typeName) {
+        if (typeName.length() != 4) {
+            throw new IllegalArgumentException("Bad type name: " + typeName);
         }
-
-        return val;
+        int result = 0;
+        for (int i = 0; i < 4; ++i) {
+            result = ((result << 8) | (typeName.charAt(i) & 0xff));
+        }
+        return result;
     }
 
     /**
@@ -139,4 +135,3 @@
     }
 
 }
-
diff --git a/luni/src/main/java/java/net/URLClassLoader.java b/luni/src/main/java/java/net/URLClassLoader.java
index 1bf2777..4b192cf 100644
--- a/luni/src/main/java/java/net/URLClassLoader.java
+++ b/luni/src/main/java/java/net/URLClassLoader.java
@@ -27,6 +27,7 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charsets;
 import java.security.CodeSource;
 import java.security.PermissionCollection;
 import java.security.SecureClassLoader;
@@ -72,10 +73,9 @@
             try {
                 // Add mappings from resource to jar file
                 String parentURLString = getParentURL(url).toExternalForm();
-                String prefix = "jar:"
-                        + parentURLString + "/";
+                String prefix = "jar:" + parentURLString + "/";
                 is = jf.getInputStream(indexEntry);
-                in = new BufferedReader(new InputStreamReader(is, "UTF8"));
+                in = new BufferedReader(new InputStreamReader(is, Charsets.UTF_8));
                 HashMap<String, ArrayList<URL>> pre_map = new HashMap<String, ArrayList<URL>>();
                 // Ignore the 2 first lines (index version)
                 if (in.readLine() == null) return null;
diff --git a/luni/src/main/java/java/nio/charset/ModifiedUtf8.java b/luni/src/main/java/java/nio/charset/ModifiedUtf8.java
index f4233ef..fd79565 100644
--- a/luni/src/main/java/java/nio/charset/ModifiedUtf8.java
+++ b/luni/src/main/java/java/nio/charset/ModifiedUtf8.java
@@ -64,7 +64,7 @@
     }
 
     /**
-     * Returns the number of bytes the modified UTF8 representation of 's' would take. Note
+     * Returns the number of bytes the modified UTF-8 representation of 's' would take. Note
      * that this is just the space for the bytes representing the characters, not the length
      * which precedes those bytes, because different callers represent the length differently,
      * as two, four, or even eight bytes. If {@code shortLength} is true, we'll throw an
diff --git a/luni/src/main/java/java/security/AccessControlContext.java b/luni/src/main/java/java/security/AccessControlContext.java
index 0da6fd5..470870d 100644
--- a/luni/src/main/java/java/security/AccessControlContext.java
+++ b/luni/src/main/java/java/security/AccessControlContext.java
@@ -50,9 +50,6 @@
 
     DomainCombiner combiner;
 
-    // An AccessControlContext inherited by the current thread from its parent
-    private AccessControlContext inherited;
-
     /**
      * Constructs a new instance of {@code AccessControlContext} with the
      * specified {@code AccessControlContext} and {@code DomainCombiner}.
@@ -141,9 +138,6 @@
                 throw new AccessControlException("Permission check failed " + perm, perm);
             }
         }
-        if (inherited != null) {
-            inherited.checkPermission(perm);
-        }
     }
 
 
diff --git a/luni/src/main/java/javax/crypto/CipherInputStream.java b/luni/src/main/java/javax/crypto/CipherInputStream.java
index 8ad0b84..d838205 100644
--- a/luni/src/main/java/javax/crypto/CipherInputStream.java
+++ b/luni/src/main/java/javax/crypto/CipherInputStream.java
@@ -35,8 +35,9 @@
  */
 public class CipherInputStream extends FilterInputStream {
 
+    private static final int I_BUFFER_SIZE = 20;
+
     private final Cipher cipher;
-    private final int I_BUFFER_SIZE = 20;
     private final byte[] i_buffer = new byte[I_BUFFER_SIZE];
     private int index; // index of the bytes to return from o_buffer
     private byte[] o_buffer;
diff --git a/luni/src/main/java/javax/crypto/spec/SecretKeySpec.java b/luni/src/main/java/javax/crypto/spec/SecretKeySpec.java
index cb70643..1868917 100644
--- a/luni/src/main/java/javax/crypto/spec/SecretKeySpec.java
+++ b/luni/src/main/java/javax/crypto/spec/SecretKeySpec.java
@@ -41,7 +41,6 @@
 
     private final byte[] key;
     private final String algorithm;
-    private final String format = "RAW";
 
     /**
      * Creates a new <code>SecretKeySpec</code> for the specified key data and
@@ -127,7 +126,7 @@
      * @return the format name "RAW".
      */
     public String getFormat() {
-        return format;
+        return "RAW";
     }
 
     /**
diff --git a/luni/src/main/java/libcore/util/ZoneInfo.java b/luni/src/main/java/libcore/util/ZoneInfo.java
index 95ebaa9..5a8caf2 100644
--- a/luni/src/main/java/libcore/util/ZoneInfo.java
+++ b/luni/src/main/java/libcore/util/ZoneInfo.java
@@ -104,7 +104,7 @@
         long currentUnixTime = System.currentTimeMillis() / 1000;
         if (mTransitions.length > 0) {
             // (We're really dealing with uint32_t values, so long is most convenient in Java.)
-            long latestScheduleTime = mTransitions[mTransitions.length - 1] & 0xffffffff;
+            long latestScheduleTime = ((long) mTransitions[mTransitions.length - 1]) & 0xffffffff;
             if (currentUnixTime < latestScheduleTime) {
                 usesDst = true;
             }
diff --git a/luni/src/main/java/org/apache/harmony/lang/annotation/AnnotationFactory.java b/luni/src/main/java/org/apache/harmony/lang/annotation/AnnotationFactory.java
index 69237c0..4667416 100644
--- a/luni/src/main/java/org/apache/harmony/lang/annotation/AnnotationFactory.java
+++ b/luni/src/main/java/org/apache/harmony/lang/annotation/AnnotationFactory.java
@@ -256,14 +256,18 @@
      * @return string representation of this annotation
      */
     public String toString() {
-        String res = "@" + klazz.getName() + "(";
-        for(int i = 0; i < elements.length; i++) {
-            if ( i != 0 ) {
-                res += ", ";
+        StringBuilder result = new StringBuilder();
+        result.append('@');
+        result.append(klazz.getName());
+        result.append('(');
+        for(int i = 0; i < elements.length; ++i) {
+            if (i != 0) {
+                result.append(", ");
             }
-            res += elements[i].toString();;
+            result.append(elements[i]);
         }
-        return res + ")";
+        result.append(')');
+        return result.toString();
     }
 
     /**
diff --git a/luni/src/main/java/org/apache/harmony/luni/lang/reflect/GenericSignatureParser.java b/luni/src/main/java/org/apache/harmony/luni/lang/reflect/GenericSignatureParser.java
index d69f602..490daaf 100644
--- a/luni/src/main/java/org/apache/harmony/luni/lang/reflect/GenericSignatureParser.java
+++ b/luni/src/main/java/org/apache/harmony/luni/lang/reflect/GenericSignatureParser.java
@@ -125,11 +125,11 @@
         } else {
             if(genericDecl instanceof Class) {
                 Class c = (Class) genericDecl;
-                this.formalTypeParameters = ListOfVariables.empty;
+                this.formalTypeParameters = ListOfVariables.EMPTY;
                 this.superclassType = c.getSuperclass();
                 this.interfaceTypes = new ListOfTypes(c.getInterfaces());
             } else {
-                this.formalTypeParameters = ListOfVariables.empty;
+                this.formalTypeParameters = ListOfVariables.EMPTY;
                 this.superclassType = Object.class;
                 this.interfaceTypes = ListOfTypes.EMPTY;
             }
@@ -151,12 +151,12 @@
         } else {
             if(genericDecl instanceof Method) {
                 Method m = (Method) genericDecl;
-                this.formalTypeParameters = ListOfVariables.empty;
+                this.formalTypeParameters = ListOfVariables.EMPTY;
                 this.parameterTypes = new ListOfTypes(m.getParameterTypes());
                 this.exceptionTypes = new ListOfTypes(m.getExceptionTypes());
                 this.returnType = m.getReturnType();
             } else {
-                this.formalTypeParameters = ListOfVariables.empty;
+                this.formalTypeParameters = ListOfVariables.EMPTY;
                 this.parameterTypes = ListOfTypes.EMPTY;
                 this.exceptionTypes = ListOfTypes.EMPTY;
                 this.returnType = void.class;
@@ -179,11 +179,11 @@
         } else {
             if(genericDecl instanceof Constructor) {
                 Constructor c = (Constructor) genericDecl;
-                this.formalTypeParameters = ListOfVariables.empty;
+                this.formalTypeParameters = ListOfVariables.EMPTY;
                 this.parameterTypes = new ListOfTypes(c.getParameterTypes());
                 this.exceptionTypes = new ListOfTypes(c.getExceptionTypes());
             } else {
-                this.formalTypeParameters = ListOfVariables.empty;
+                this.formalTypeParameters = ListOfVariables.EMPTY;
                 this.parameterTypes = ListOfTypes.EMPTY;
                 this.exceptionTypes = ListOfTypes.EMPTY;
             }
diff --git a/luni/src/main/java/org/apache/harmony/luni/lang/reflect/ListOfVariables.java b/luni/src/main/java/org/apache/harmony/luni/lang/reflect/ListOfVariables.java
index 32b4d0c..0e757ac 100644
--- a/luni/src/main/java/org/apache/harmony/luni/lang/reflect/ListOfVariables.java
+++ b/luni/src/main/java/org/apache/harmony/luni/lang/reflect/ListOfVariables.java
@@ -20,10 +20,9 @@
 import java.util.ArrayList;
 
 class ListOfVariables {
-    public static final TypeVariable[] empty = new ImplForVariable[0];
+    public static final TypeVariable[] EMPTY = new ImplForVariable[0];
 
     ArrayList<TypeVariable<?>> array = new ArrayList<TypeVariable<?>>();
-    int n = 0;
 
     void add (TypeVariable<?> elem) {
         array.add(elem);
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketInputStream.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketInputStream.java
index 950518b..0e9f0e7 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketInputStream.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketInputStream.java
@@ -26,16 +26,15 @@
  * for SSLSocket. It accumulates the application data
  * received by SSL protocol.
  */
-public final class SSLSocketInputStream
-        extends InputStream {
+public final class SSLSocketInputStream extends InputStream {
 
     // The size of the internal data buffer.
     // It should not be less than maximum data chunk enclosed
     // in one ssl packet.
-    private final int size = SSLRecordProtocol.MAX_DATA_LENGTH;
+    private static final int BUFFER_SIZE = SSLRecordProtocol.MAX_DATA_LENGTH;
 
     // Internal buffer accumulating the received application data
-    private byte[] buffer = new byte[size];
+    private byte[] buffer = new byte[BUFFER_SIZE];
 
     // position of the next byte to read from the buffer
     private int pos;
@@ -142,10 +141,10 @@
         return i;
     }
 
-    // The helper class devivering the application data from the record layer
+    // The helper class delivering the application data from the record layer
     // to this input stream.
     // It 'adapts' the InputStream interface to Appendable, which is used for
-    // transmition of income data from the record protocol to its clients.
+    // transmission of income data from the record protocol to its clients.
     private class Adapter implements org.apache.harmony.xnet.provider.jsse.Appendable {
         /**
          * Appends the data to the stream.
@@ -154,20 +153,20 @@
          */
         public void append(byte[] src) {
             int length = src.length;
-            if (size - (end - pos) < length) {
+            if (BUFFER_SIZE - (end - pos) < length) {
                 // If the size of the buffer is greater than or equals to
                 // SSLRecordProtocol.MAX_DATA_LENGTH this situation will
                 // happen iff:
                 // 1. the length of received data fragment is greater
                 // than allowed by the spec
-                // 2. it is rehandhaking stage and we have got several
+                // 2. it is rehandshaking stage and we have got several
                 // extra app data messages.
                 // In any case it is better to throw alert exception.
                 throw new AlertException(AlertProtocol.INTERNAL_ERROR,
                         new SSLException("Could not accept income app data."));
             }
-            if (end + length > size) {
-                // move the content of the buffer to the beginnig
+            if (end + length > BUFFER_SIZE) {
+                // move the content of the buffer to the beginning
                 System.arraycopy(buffer, pos, buffer, 0, end-pos);
                 end -= pos;
                 pos = 0;
@@ -177,4 +176,3 @@
         }
     }
 }
-
diff --git a/luni/src/main/java/org/xml/sax/helpers/XMLReaderFactory.java b/luni/src/main/java/org/xml/sax/helpers/XMLReaderFactory.java
index 1d750b6..54117bb 100644
--- a/luni/src/main/java/org/xml/sax/helpers/XMLReaderFactory.java
+++ b/luni/src/main/java/org/xml/sax/helpers/XMLReaderFactory.java
@@ -10,6 +10,7 @@
 import java.io.BufferedReader;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.nio.charset.Charsets;
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
 
@@ -125,7 +126,7 @@
             in = loader.getResourceAsStream (service);
 
         if (in != null) {
-            reader = new BufferedReader (new InputStreamReader (in, "UTF8"));
+            reader = new BufferedReader (new InputStreamReader (in, Charsets.UTF_8));
             className = reader.readLine ();
             in.close ();
         }
diff --git a/xml/src/main/java/org/kxml2/io/KXmlParser.java b/xml/src/main/java/org/kxml2/io/KXmlParser.java
index 4b4f328..7a2d052 100644
--- a/xml/src/main/java/org/kxml2/io/KXmlParser.java
+++ b/xml/src/main/java/org/kxml2/io/KXmlParser.java
@@ -38,11 +38,11 @@
  */
 public class KXmlParser implements XmlPullParser, Closeable {
 
-    private final String PROPERTY_XMLDECL_VERSION
+    private static final String PROPERTY_XMLDECL_VERSION
             = "http://xmlpull.org/v1/doc/properties.html#xmldecl-version";
-    private final String PROPERTY_XMLDECL_STANDALONE
+    private static final String PROPERTY_XMLDECL_STANDALONE
             = "http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone";
-    private final String PROPERTY_LOCATION = "http://xmlpull.org/v1/doc/properties.html#location";
+    private static final String PROPERTY_LOCATION = "http://xmlpull.org/v1/doc/properties.html#location";
     private static final String FEATURE_RELAXED = "http://xmlpull.org/v1/doc/features.html#relaxed";
 
     private static final Map<String, String> DEFAULT_ENTITIES = new HashMap<String, String>();