tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1360855 - in /tomcat/trunk/java/org/apache/catalina/connector: Connector.java CoyoteAdapter.java CoyotePrincipal.java InputBuffer.java MapperListener.java OutputBuffer.java Request.java Response.java
Date Thu, 12 Jul 2012 18:42:58 GMT
Author: markt
Date: Thu Jul 12 18:42:57 2012
New Revision: 1360855

URL: http://svn.apache.org/viewvc?rev=1360855&view=rev
Log:
Code clean-up for o.a.catalina.connector
 - Add final prompted by UCDetector
 - Java 7 use of <>

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/Connector.java
    tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
    tomcat/trunk/java/org/apache/catalina/connector/CoyotePrincipal.java
    tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java
    tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java
    tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java
    tomcat/trunk/java/org/apache/catalina/connector/Request.java
    tomcat/trunk/java/org/apache/catalina/connector/Response.java

Modified: tomcat/trunk/java/org/apache/catalina/connector/Connector.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Connector.java?rev=1360855&r1=1360854&r2=1360855&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Connector.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Connector.java Thu Jul 12 18:42:57 2012
@@ -67,12 +67,15 @@ public class Connector extends Lifecycle
     public Connector(String protocol) {
         setProtocol(protocol);
         // Instantiate protocol handler
+        ProtocolHandler p = null;
         try {
             Class<?> clazz = Class.forName(protocolHandlerClassName);
-            this.protocolHandler = (ProtocolHandler) clazz.newInstance();
+            p = (ProtocolHandler) clazz.newInstance();
         } catch (Exception e) {
             log.error(sm.getString(
                     "coyoteConnector.protocolHandlerInstantiationFailed"), e);
+        } finally {
+            this.protocolHandler = p;
         }
     }
 
@@ -210,7 +213,7 @@ public class Connector extends Lifecycle
     /**
      * Coyote protocol handler.
      */
-    protected ProtocolHandler protocolHandler = null;
+    protected final ProtocolHandler protocolHandler;
 
 
     /**
@@ -222,13 +225,14 @@ public class Connector extends Lifecycle
      /**
       * Mapper.
       */
-     protected Mapper mapper = new Mapper();
+     protected final Mapper mapper = new Mapper();
 
 
      /**
       * Mapper listener.
       */
-     protected MapperListener mapperListener = new MapperListener(mapper, this);
+     protected final MapperListener mapperListener =
+             new MapperListener(mapper, this);
 
 
      /**
@@ -243,8 +247,8 @@ public class Connector extends Lifecycle
      protected boolean useBodyEncodingForURI = false;
 
 
-     protected static HashMap<String,String> replacements =
-         new HashMap<String,String>();
+     protected static final HashMap<String,String> replacements =
+             new HashMap<>();
      static {
          replacements.put("acceptCount", "backlog");
          replacements.put("connectionLinger", "soLinger");
@@ -490,7 +494,7 @@ public class Connector extends Lifecycle
 
     public void setParseBodyMethods(String methods) {
 
-        HashSet<String> methodSet = new HashSet<String>();
+        HashSet<String> methodSet = new HashSet<>();
 
         if( null != methods ) {
             methodSet.addAll(Arrays.asList(methods.split("\\s*,\\s*")));

Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=1360855&r1=1360854&r2=1360855&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Thu Jul 12 18:42:57
2012
@@ -100,7 +100,7 @@ public class CoyoteAdapter implements Ad
     /**
      * The CoyoteConnector with which this processor is associated.
      */
-    private Connector connector = null;
+    private final Connector connector;
 
 
     /**
@@ -113,7 +113,7 @@ public class CoyoteAdapter implements Ad
     /**
      * Encoder for the Location URL in HTTP redirects.
      */
-    protected static URLEncoder urlEncoder;
+    protected static final URLEncoder urlEncoder;
 
 
     // ----------------------------------------------------- Static Initializer

Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyotePrincipal.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyotePrincipal.java?rev=1360855&r1=1360854&r2=1360855&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyotePrincipal.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyotePrincipal.java Thu Jul 12 18:42:57
2012
@@ -47,7 +47,7 @@ public class CoyotePrincipal implements 
     /**
      * The username of the user represented by this Principal.
      */
-    protected String name = null;
+    protected final String name;
 
     @Override
     public String getName() {

Modified: tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java?rev=1360855&r1=1360854&r2=1360855&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java Thu Jul 12 18:42:57 2012
@@ -108,8 +108,7 @@ public class InputBuffer extends Reader
     /**
      * List of encoders.
      */
-    protected HashMap<String,B2CConverter> encoders =
-        new HashMap<String,B2CConverter>();
+    protected final HashMap<String,B2CConverter> encoders = new HashMap<>();
 
 
     /**
@@ -133,7 +132,7 @@ public class InputBuffer extends Reader
     /**
      * Buffer size.
      */
-    private int size = -1;
+    private final int size;
 
 
     // ----------------------------------------------------------- Constructors

Modified: tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java?rev=1360855&r1=1360854&r2=1360855&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java Thu Jul 12 18:42:57
2012
@@ -52,12 +52,12 @@ public class MapperListener extends Life
     /**
      * Associated mapper.
      */
-    private Mapper mapper = null;
+    private final Mapper mapper;
 
     /**
      * Associated connector
      */
-    private Connector connector = null;
+    private final Connector connector;
 
 
     /**

Modified: tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java?rev=1360855&r1=1360854&r2=1360855&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java Thu Jul 12 18:42:57
2012
@@ -114,8 +114,7 @@ public class OutputBuffer extends Writer
     /**
      * List of encoders.
      */
-    protected HashMap<String, C2BConverter> encoders =
-        new HashMap<String, C2BConverter>();
+    protected final HashMap<String, C2BConverter> encoders = new HashMap<>();
 
 
     /**

Modified: tomcat/trunk/java/org/apache/catalina/connector/Request.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Request.java?rev=1360855&r1=1360854&r2=1360855&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Request.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Request.java Thu Jul 12 18:42:57 2012
@@ -172,7 +172,7 @@ public class Request
      * Notice that because SimpleDateFormat is not thread-safe, we can't
      * declare formats[] as a static variable.
      */
-    protected SimpleDateFormat formats[] = {
+    protected final SimpleDateFormat formats[] = {
         new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
         new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
         new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
@@ -182,14 +182,13 @@ public class Request
     /**
      * The default Locale if none are specified.
      */
-    protected static Locale defaultLocale = Locale.getDefault();
+    protected static final Locale defaultLocale = Locale.getDefault();
 
 
     /**
      * The attributes associated with this Request, keyed by attribute name.
      */
-    protected HashMap<String, Object> attributes =
-        new HashMap<String, Object>();
+    protected final HashMap<String, Object> attributes = new HashMap<>();
 
 
     /**
@@ -202,21 +201,20 @@ public class Request
     /**
      * List of read only attributes for this Request.
      */
-    private final HashMap<String,Object> readOnlyAttributes =
-        new HashMap<String,Object>();
+    private final HashMap<String,Object> readOnlyAttributes = new HashMap<>();
 
 
     /**
      * The preferred Locales associated with this Request.
      */
-    protected ArrayList<Locale> locales = new ArrayList<Locale>();
+    protected final ArrayList<Locale> locales = new ArrayList<>();
 
 
     /**
      * Internal notes associated with this request by Catalina components
      * and event listeners.
      */
-    private transient HashMap<String, Object> notes = new HashMap<String, Object>();
+    private final transient HashMap<String, Object> notes = new HashMap<>();
 
 
     /**
@@ -246,14 +244,14 @@ public class Request
     /**
      * The associated input buffer.
      */
-    protected InputBuffer inputBuffer = new InputBuffer();
+    protected final InputBuffer inputBuffer = new InputBuffer();
 
 
     /**
      * ServletInputStream.
      */
     protected CoyoteInputStream inputStream =
-        new CoyoteInputStream(inputBuffer);
+            new CoyoteInputStream(inputBuffer);
 
 
     /**
@@ -307,14 +305,14 @@ public class Request
     /**
      * Post data buffer.
      */
-    protected static int CACHED_POST_LEN = 8192;
+    protected static final int CACHED_POST_LEN = 8192;
     protected byte[] postData = null;
 
 
     /**
      * Hash map used in the getParametersMap method.
      */
-    protected ParameterMap<String, String[]> parameterMap = new ParameterMap<String,
String[]>();
+    protected ParameterMap<String, String[]> parameterMap = new ParameterMap<>();
 
 
     /**
@@ -421,7 +419,7 @@ public class Request
     /**
      * Path parameters
      */
-    protected Map<String,String> pathParameters = new HashMap<String, String>();
+    protected final Map<String,String> pathParameters = new HashMap<>();
 
     // --------------------------------------------------------- Public Methods
 
@@ -504,7 +502,7 @@ public class Request
         requestedSessionURL = false;
 
         if (Globals.IS_SECURITY_ENABLED || Connector.RECYCLE_FACADES) {
-            parameterMap = new ParameterMap<String, String[]>();
+            parameterMap = new ParameterMap<>();
         } else {
             parameterMap.setLocked(false);
             parameterMap.clear();
@@ -637,7 +635,7 @@ public class Request
     /**
      * Mapping data.
      */
-    protected MappingData mappingData = new MappingData();
+    protected final MappingData mappingData = new MappingData();
 
     /**
      * Return mapping data.
@@ -971,7 +969,7 @@ public class Request
         }
         // Take a copy to prevent ConncurrentModificationExceptions if used to
         // remove attributes
-        Set<String> names = new HashSet<String>();
+        Set<String> names = new HashSet<>();
         names.addAll(attributes.keySet());
         return Collections.enumeration(names);
     }
@@ -1067,7 +1065,7 @@ public class Request
         if (locales.size() > 0) {
             return Collections.enumeration(locales);
         }
-        ArrayList<Locale> results = new ArrayList<Locale>();
+        ArrayList<Locale> results = new ArrayList<>();
         results.add(defaultLocale);
         return Collections.enumeration(results);
 
@@ -2544,7 +2542,7 @@ public class Request
             upload.setFileSizeMax(mce.getMaxFileSize());
             upload.setSizeMax(mce.getMaxRequestSize());
 
-            parts = new ArrayList<Part>();
+            parts = new ArrayList<>();
             try {
                 List<FileItem> items = upload.parseRequest(this);
                 int maxPostSize = getConnector().getMaxPostSize();
@@ -3019,7 +3017,7 @@ public class Request
         // a local collection, sorted by the quality value (so we can
         // add Locales in descending order).  The values will be ArrayLists
         // containing the corresponding Locales to be added
-        TreeMap<Double, ArrayList<Locale>> locales = new TreeMap<Double, ArrayList<Locale>>();
+        TreeMap<Double, ArrayList<Locale>> locales = new TreeMap<>();
 
         // Preprocess the value to remove all whitespace
         int white = value.indexOf(' ');
@@ -3110,7 +3108,7 @@ public class Request
             Double key = new Double(-quality);  // Reverse the order
             ArrayList<Locale> values = locales.get(key);
             if (values == null) {
-                values = new ArrayList<Locale>();
+                values = new ArrayList<>();
                 locales.put(key, values);
             }
             values.add(locale);
@@ -3151,7 +3149,7 @@ public class Request
     }
 
     private static final Map<String, SpecialAttributeAdapter> specialAttributes
-        = new HashMap<String, SpecialAttributeAdapter>();
+        = new HashMap<>();
 
     static {
         specialAttributes.put(Globals.DISPATCHER_TYPE_ATTR,

Modified: tomcat/trunk/java/org/apache/catalina/connector/Response.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Response.java?rev=1360855&r1=1360854&r2=1360855&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Response.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Response.java Thu Jul 12 18:42:57 2012
@@ -215,13 +215,13 @@ public class Response
     /**
      * URL encoder.
      */
-    protected UEncoder urlEncoder = new UEncoder();
+    protected final UEncoder urlEncoder = new UEncoder();
 
 
     /**
      * Recyclable buffer to hold the redirect URL.
      */
-    protected CharChunk redirectURLCC = new CharChunk();
+    protected final CharChunk redirectURLCC = new CharChunk();
 
 
     // --------------------------------------------------------- Public Methods
@@ -826,7 +826,7 @@ public class Response
 
         MimeHeaders headers = coyoteResponse.getMimeHeaders();
         int n = headers.size();
-        List<String> result = new ArrayList<String>(n);
+        List<String> result = new ArrayList<>(n);
         for (int i = 0; i < n; i++) {
             result.add(headers.getName(i).toString());
         }
@@ -846,7 +846,7 @@ public class Response
 
         Enumeration<String> enumeration =
             coyoteResponse.getMimeHeaders().values(name);
-        Vector<String> result = new Vector<String>();
+        Vector<String> result = new Vector<>();
         while (enumeration.hasMoreElements()) {
             result.addElement(enumeration.nextElement());
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message