hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1698012 - /httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java
Date Wed, 26 Aug 2015 22:01:27 GMT
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);



Mime
View raw message