6929645: Address various findbugs warnings in langtools
authordarcy
Thu, 25 Feb 2010 11:04:11 -0800
changeset 5003 fd0b30cdbe5c
parent 5002 12a9e8562200
child 5004 6c2694dc2da0
6929645: Address various findbugs warnings in langtools Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/apt/comp/Apt.java
langtools/src/share/classes/com/sun/tools/apt/mirror/declaration/AnnotationProxyMaker.java
langtools/src/share/classes/com/sun/tools/apt/mirror/declaration/DeclarationImpl.java
langtools/src/share/classes/com/sun/tools/javac/model/AnnotationProxyMaker.java
langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
--- a/langtools/src/share/classes/com/sun/tools/apt/comp/Apt.java	Thu Feb 25 09:42:35 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/apt/comp/Apt.java	Thu Feb 25 11:04:11 2010 -0800
@@ -457,8 +457,10 @@
                 throw new UsageMessageNeededException();
 
             try {
-                for(AnnotationProcessorFactory apFactory: factoryToAnnotation.keySet()) {
-                    AnnotationProcessor processor = apFactory.getProcessorFor(factoryToAnnotation.get(apFactory),
+                for(Map.Entry<AnnotationProcessorFactory, Set<AnnotationTypeDeclaration>> entry :
+                        factoryToAnnotation.entrySet()) {
+                    AnnotationProcessorFactory  apFactory = entry.getKey();
+                    AnnotationProcessor processor = apFactory.getProcessorFor(entry.getValue(),
                                                                               trivAPE);
                     if (processor != null)
                         processors.add(processor);
--- a/langtools/src/share/classes/com/sun/tools/apt/mirror/declaration/AnnotationProxyMaker.java	Thu Feb 25 09:42:35 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/apt/mirror/declaration/AnnotationProxyMaker.java	Thu Feb 25 11:04:11 2010 -0800
@@ -270,7 +270,7 @@
      * The toString, hashCode, and equals methods foward to the underlying
      * type.
      */
-    private static class MirroredTypeExceptionProxy extends ExceptionProxy {
+    private static final class MirroredTypeExceptionProxy extends ExceptionProxy {
         private static final long serialVersionUID = 6662035281599933545L;
 
         private MirroredTypeException ex;
@@ -312,7 +312,7 @@
      * The toString, hashCode, and equals methods foward to the underlying
      * types.
      */
-    private static class MirroredTypesExceptionProxy extends ExceptionProxy {
+    private static final class MirroredTypesExceptionProxy extends ExceptionProxy {
         private static final long serialVersionUID = -6670822532616693951L;
 
         private MirroredTypesException ex;
--- a/langtools/src/share/classes/com/sun/tools/apt/mirror/declaration/DeclarationImpl.java	Thu Feb 25 09:42:35 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/apt/mirror/declaration/DeclarationImpl.java	Thu Feb 25 11:04:11 2010 -0800
@@ -58,7 +58,7 @@
     protected final AptEnv env;
     public final Symbol sym;
 
-    protected static DeclarationFilter identityFilter =
+    protected static final DeclarationFilter identityFilter =
             new DeclarationFilter();
 
 
--- a/langtools/src/share/classes/com/sun/tools/javac/model/AnnotationProxyMaker.java	Thu Feb 25 09:42:35 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/model/AnnotationProxyMaker.java	Thu Feb 25 11:04:11 2010 -0800
@@ -26,6 +26,8 @@
 package com.sun.tools.javac.model;
 
 import com.sun.tools.javac.util.*;
+import java.io.ObjectInputStream;
+import java.io.IOException;
 import java.lang.annotation.*;
 import java.lang.reflect.Array;
 import java.lang.reflect.Method;
@@ -268,10 +270,10 @@
      * The toString, hashCode, and equals methods foward to the underlying
      * type.
      */
-    private static class MirroredTypeExceptionProxy extends ExceptionProxy {
+    private static final class MirroredTypeExceptionProxy extends ExceptionProxy {
         static final long serialVersionUID = 269;
 
-        private transient final TypeMirror type;
+        private transient TypeMirror type;
         private final String typeString;
 
         MirroredTypeExceptionProxy(TypeMirror t) {
@@ -296,6 +298,13 @@
         protected RuntimeException generateException() {
             return new MirroredTypeException(type);
         }
+
+        // Explicitly set all transient fields.
+        private void readObject(ObjectInputStream s)
+            throws IOException, ClassNotFoundException {
+            s.defaultReadObject();
+            type = null;
+        }
     }
 
 
@@ -304,10 +313,10 @@
      * The toString, hashCode, and equals methods foward to the underlying
      * types.
      */
-    private static class MirroredTypesExceptionProxy extends ExceptionProxy {
+    private static final class MirroredTypesExceptionProxy extends ExceptionProxy {
         static final long serialVersionUID = 269;
 
-        private transient final List<TypeMirror> types;
+        private transient List<TypeMirror> types;
         private final String typeStrings;
 
         MirroredTypesExceptionProxy(List<TypeMirror> ts) {
@@ -333,5 +342,12 @@
         protected RuntimeException generateException() {
             return new MirroredTypesException(types);
         }
+
+        // Explicitly set all transient fields.
+        private void readObject(ObjectInputStream s)
+            throws IOException, ClassNotFoundException {
+            s.defaultReadObject();
+            types = null;
+        }
     }
 }
--- a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Thu Feb 25 09:42:35 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Thu Feb 25 11:04:11 2010 -0800
@@ -690,10 +690,12 @@
             ProcessorState ps = psi.next();
             Set<String>  matchedNames = new HashSet<String>();
             Set<TypeElement> typeElements = new LinkedHashSet<TypeElement>();
-            for (String unmatchedAnnotationName : unmatchedAnnotations.keySet()) {
+
+            for (Map.Entry<String, TypeElement> entry: unmatchedAnnotations.entrySet()) {
+                String unmatchedAnnotationName = entry.getKey();
                 if (ps.annotationSupported(unmatchedAnnotationName) ) {
                     matchedNames.add(unmatchedAnnotationName);
-                    TypeElement te = unmatchedAnnotations.get(unmatchedAnnotationName);
+                    TypeElement te = entry.getValue();
                     if (te != null)
                         typeElements.add(te);
                 }
@@ -790,7 +792,7 @@
                                      List<JCCompilationUnit> roots,
                                      List<ClassSymbol> classSymbols,
                                      Iterable<? extends PackageSymbol> pckSymbols)
-    throws IOException {
+        throws IOException {
 
         log = Log.instance(context);
         // Writer for -XprintRounds and -XprintProcessorInfo data
@@ -1218,7 +1220,7 @@
         return false;
     }
 
-    private class AnnotationCollector extends TreeScanner {
+    private static class AnnotationCollector extends TreeScanner {
         List<JCTree> path = List.nil();
         static final boolean verbose = false;
         List<JCAnnotation> annotations = List.nil();