tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1749866 - in /tomcat/trunk: java/org/apache/catalina/core/ java/org/apache/catalina/tribes/tipis/ java/org/apache/jasper/el/ java/org/apache/tomcat/util/collections/ java/org/apache/tomcat/util/net/ webapps/examples/WEB-INF/classes/websock...
Date Thu, 23 Jun 2016 11:32:11 GMT
Author: markt
Date: Thu Jun 23 11:32:11 2016
New Revision: 1749866

URL: http://svn.apache.org/viewvc?rev=1749866&view=rev
Log:
Use Objects.requireNonNull() to simplify code

Modified:
    tomcat/trunk/java/org/apache/catalina/core/AccessLogAdapter.java
    tomcat/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java
    tomcat/trunk/java/org/apache/jasper/el/ELResolverImpl.java
    tomcat/trunk/java/org/apache/tomcat/util/collections/ManagedConcurrentWeakHashMap.java
    tomcat/trunk/java/org/apache/tomcat/util/net/SocketProcessorBase.java
    tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java

Modified: tomcat/trunk/java/org/apache/catalina/core/AccessLogAdapter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/AccessLogAdapter.java?rev=1749866&r1=1749865&r2=1749866&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/AccessLogAdapter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/AccessLogAdapter.java Thu Jun 23 11:32:11 2016
@@ -17,6 +17,7 @@
 package org.apache.catalina.core;
 
 import java.util.Arrays;
+import java.util.Objects;
 
 import org.apache.catalina.AccessLog;
 import org.apache.catalina.connector.Request;
@@ -30,16 +31,12 @@ public class AccessLogAdapter implements
     private AccessLog[] logs;
 
     public AccessLogAdapter(AccessLog log) {
-        if (log == null) {
-            throw new NullPointerException();
-        }
+        Objects.requireNonNull(log);
         logs = new AccessLog[] { log };
     }
 
     public void add(AccessLog log) {
-        if (log == null) {
-            throw new NullPointerException();
-        }
+        Objects.requireNonNull(log);
         AccessLog newArray[] = Arrays.copyOf(logs, logs.length + 1);
         newArray[newArray.length - 1] = log;
         logs = newArray;

Modified: tomcat/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java?rev=1749866&r1=1749865&r2=1749866&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java (original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/tipis/AbstractReplicatedMap.java Thu Jun
23 11:32:11 2016
@@ -27,6 +27,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -1121,9 +1122,7 @@ public abstract class AbstractReplicated
 
     @Override
     public boolean containsValue(Object value) {
-        if (value == null) {
-            throw new NullPointerException();
-        }
+        Objects.requireNonNull(value);
         Iterator<Map.Entry<K,MapEntry<K,V>>> i = innerMap.entrySet().iterator();
         while (i.hasNext()) {
             Map.Entry<K,MapEntry<K,V>> e = i.next();

Modified: tomcat/trunk/java/org/apache/jasper/el/ELResolverImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/el/ELResolverImpl.java?rev=1749866&r1=1749865&r2=1749866&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/el/ELResolverImpl.java (original)
+++ tomcat/trunk/java/org/apache/jasper/el/ELResolverImpl.java Thu Jun 23 11:32:11 2016
@@ -18,6 +18,7 @@
 package org.apache.jasper.el;
 
 import java.util.Iterator;
+import java.util.Objects;
 
 import javax.el.ELContext;
 import javax.el.ELException;
@@ -40,9 +41,7 @@ public final class ELResolverImpl extend
 
     @Override
     public Object getValue(ELContext context, Object base, Object property) {
-        if (context == null) {
-            throw new NullPointerException();
-        }
+        Objects.requireNonNull(context);
 
         if (base == null) {
             context.setPropertyResolved(base, property);
@@ -64,9 +63,7 @@ public final class ELResolverImpl extend
 
     @Override
     public Class<?> getType(ELContext context, Object base, Object property) {
-        if (context == null) {
-            throw new NullPointerException();
-        }
+        Objects.requireNonNull(context);
 
         if (base == null) {
             context.setPropertyResolved(base, property);
@@ -90,9 +87,7 @@ public final class ELResolverImpl extend
     @Override
     public void setValue(ELContext context, Object base, Object property,
             Object value) {
-        if (context == null) {
-            throw new NullPointerException();
-        }
+        Objects.requireNonNull(context);
 
         if (base == null) {
             context.setPropertyResolved(base, property);
@@ -107,9 +102,7 @@ public final class ELResolverImpl extend
 
     @Override
     public boolean isReadOnly(ELContext context, Object base, Object property) {
-        if (context == null) {
-            throw new NullPointerException();
-        }
+        Objects.requireNonNull(context);
 
         if (base == null) {
             context.setPropertyResolved(base, property);

Modified: tomcat/trunk/java/org/apache/tomcat/util/collections/ManagedConcurrentWeakHashMap.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/collections/ManagedConcurrentWeakHashMap.java?rev=1749866&r1=1749865&r2=1749866&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/collections/ManagedConcurrentWeakHashMap.java
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/collections/ManagedConcurrentWeakHashMap.java
Thu Jun 23 11:32:11 2016
@@ -24,6 +24,7 @@ import java.util.AbstractSet;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -122,12 +123,6 @@ public class ManagedConcurrentWeakHashMa
         return new Key(key, null);
     }
 
-    private static void checkNotNull(Object value) {
-        if (value == null) {
-            throw new NullPointerException();
-        }
-    }
-
     @Override
     public int size() {
         return map.size();
@@ -164,7 +159,7 @@ public class ManagedConcurrentWeakHashMa
 
     @Override
     public V put(K key, V value) {
-        checkNotNull(value);
+        Objects.requireNonNull(value);
         return map.put(createStoreKey(key), value);
     }
 
@@ -183,7 +178,7 @@ public class ManagedConcurrentWeakHashMa
 
     @Override
     public V putIfAbsent(K key, V value) {
-        checkNotNull(value);
+        Objects.requireNonNull(value);
         Key storeKey = createStoreKey(key);
         V oldValue = map.putIfAbsent(storeKey, value);
         if (oldValue != null) { // ack that key has not been stored
@@ -202,13 +197,13 @@ public class ManagedConcurrentWeakHashMa
 
     @Override
     public boolean replace(K key, V oldValue, V newValue) {
-        checkNotNull(newValue);
+        Objects.requireNonNull(newValue);
         return map.replace(createLookupKey(key), oldValue, newValue);
     }
 
     @Override
     public V replace(K key, V value) {
-        checkNotNull(value);
+        Objects.requireNonNull(value);
         return map.replace(createLookupKey(key), value);
     }
 
@@ -259,7 +254,7 @@ public class ManagedConcurrentWeakHashMa
 
                             @Override
                             public V setValue(V value) {
-                                checkNotNull(value);
+                                Objects.requireNonNull(value);
                                 return en.setValue(value);
                             }
                         };

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SocketProcessorBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SocketProcessorBase.java?rev=1749866&r1=1749865&r2=1749866&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/SocketProcessorBase.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketProcessorBase.java Thu Jun 23 11:32:11
2016
@@ -16,6 +16,7 @@
  */
 package org.apache.tomcat.util.net;
 
+import java.util.Objects;
 
 public abstract class SocketProcessorBase<S> implements Runnable {
 
@@ -28,13 +29,9 @@ public abstract class SocketProcessorBas
 
 
     public void reset(SocketWrapperBase<S> socketWrapper, SocketEvent event) {
+        Objects.requireNonNull(event);
         this.socketWrapper = socketWrapper;
-        if (event == null) {
-            // Should never happen
-            throw new NullPointerException();
-        } else {
-            this.event = event;
-        }
+        this.event = event;
     }
 
 

Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java?rev=1749866&r1=1749865&r2=1749866&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/drawboard/Room.java Thu Jun 23
11:32:11 2016
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 import java.util.Timer;
 import java.util.TimerTask;
 import java.util.concurrent.locks.ReentrantLock;
@@ -484,8 +485,8 @@ public final class Room {
          * @param content
          */
         private void sendRoomMessage(MessageType type, String content) {
-            if (content == null || type == null)
-                throw new NullPointerException();
+            Objects.requireNonNull(content);
+            Objects.requireNonNull(type);
 
             String completeMsg = String.valueOf(type.flag) + content;
 



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


Mime
View raw message