You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2015/08/27 00:01:27 UTC

svn commit: r1698012 - /httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java

Author: ggregory
Date: Wed Aug 26 22:01:26 2015
New Revision: 1698012

URL: http://svn.apache.org/r1698012
Log:
Avoid potential NPE.

Modified:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java?rev=1698012&r1=1698011&r2=1698012&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java Wed Aug 26 22:01:26 2015
@@ -217,19 +217,21 @@ public final class ContentType implement
 
     private static ContentType create(final String mimeType, final NameValuePair[] params, final boolean strict) {
         Charset charset = null;
-        for (final NameValuePair param: params) {
-            if (param.getName().equalsIgnoreCase("charset")) {
-                final String s = param.getValue();
-                if (!TextUtils.isBlank(s)) {
-                    try {
-                        charset =  Charset.forName(s);
-                    } catch (UnsupportedCharsetException ex) {
-                        if (strict) {
-                            throw ex;
+        if (params != null) {
+            for (final NameValuePair param : params) {
+                if (param.getName().equalsIgnoreCase("charset")) {
+                    final String s = param.getValue();
+                    if (!TextUtils.isBlank(s)) {
+                        try {
+                            charset = Charset.forName(s);
+                        } catch (UnsupportedCharsetException ex) {
+                            if (strict) {
+                                throw ex;
+                            }
                         }
                     }
+                    break;
                 }
-                break;
             }
         }
         return new ContentType(mimeType, charset, params != null && params.length > 0 ? params : null);