From 19f0fec393d48f2aaf02b0a7fc457395e9fb4804 Mon Sep 17 00:00:00 2001 From: Christophe SAUVEUR Date: Fri, 12 Dec 2014 18:41:11 +0100 Subject: [PATCH 1/4] Removed compilation warnings --- JSONObject.java | 11 +++++++---- Property.java | 2 +- zip/Zipper.java | 5 +++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/JSONObject.java b/JSONObject.java index d66623110..446eb3ed5 100755 --- a/JSONObject.java +++ b/JSONObject.java @@ -298,7 +298,7 @@ public JSONObject(Object bean) { */ public JSONObject(Object object, String names[]) { this(); - Class c = object.getClass(); + Class c = object.getClass(); for (int i = 0; i < names.length; i += 1) { String name = names[i]; try { @@ -631,7 +631,7 @@ public static String[] getNames(Object object) { if (object == null) { return null; } - Class klass = object.getClass(); + Class klass = object.getClass(); Field[] fields = klass.getFields(); int length = fields.length; if (length == 0) { @@ -981,7 +981,7 @@ public String optString(String key, String defaultValue) { } private void populateMap(Object bean) { - Class klass = bean.getClass(); + Class klass = bean.getClass(); // If klass is a System class then set includeSuperClass to false. @@ -1488,6 +1488,7 @@ public String toString(int indentFactor) throws JSONException { * @throws JSONException * If the value is or contains an invalid number. */ + @SuppressWarnings("unchecked") public static String valueToString(Object value) throws JSONException { if (value == null || value.equals(null)) { return "null"; @@ -1512,7 +1513,7 @@ public static String valueToString(Object value) throws JSONException { return value.toString(); } if (value instanceof Map) { - return new JSONObject((Map)value).toString(); + return new JSONObject((Map) value).toString(); } if (value instanceof Collection) { return new JSONArray((Collection) value).toString(); @@ -1535,6 +1536,7 @@ public static String valueToString(Object value) throws JSONException { * The object to wrap * @return The wrapped value */ + @SuppressWarnings("unchecked") public static Object wrap(Object object) { try { if (object == null) { @@ -1586,6 +1588,7 @@ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); } + @SuppressWarnings("unchecked") static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent) throws JSONException, IOException { if (value == null || value.equals(null)) { diff --git a/Property.java b/Property.java index 8122241e9..ad56b1f87 100644 --- a/Property.java +++ b/Property.java @@ -43,7 +43,7 @@ public class Property { public static JSONObject toJSONObject(java.util.Properties properties) throws JSONException { JSONObject jo = new JSONObject(); if (properties != null && !properties.isEmpty()) { - Enumeration enumProperties = properties.propertyNames(); + Enumeration enumProperties = properties.propertyNames(); while(enumProperties.hasMoreElements()) { String name = (String)enumProperties.nextElement(); jo.put(name, properties.getProperty(name)); diff --git a/zip/Zipper.java b/zip/Zipper.java index 48b4f1acb..0624b7d0e 100644 --- a/zip/Zipper.java +++ b/zip/Zipper.java @@ -268,6 +268,7 @@ private void write(JSONArray jsonarray) throws JSONException { * or String, or Boolean, or JSONObject.NULL, or null. * @throws JSONException */ + @SuppressWarnings("unchecked") private void writeJSON(Object value) throws JSONException { if (JSONObject.NULL.equals(value)) { write(zipNull, 3); @@ -277,9 +278,9 @@ private void writeJSON(Object value) throws JSONException { write(zipTrue, 3); } else { if (value instanceof Map) { - value = new JSONObject((Map) value); + value = new JSONObject((Map) value); } else if (value instanceof Collection) { - value = new JSONArray((Collection) value); + value = new JSONArray((Collection) value); } else if (value.getClass().isArray()) { value = new JSONArray(value); } From a06d935afa82edf6f452a59efdd96415f9c84b10 Mon Sep 17 00:00:00 2001 From: Christophe SAUVEUR Date: Sat, 21 Mar 2015 11:55:28 +0100 Subject: [PATCH 2/4] Fixed warnings without SuppressWarnings annotations --- JSONObject.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/JSONObject.java b/JSONObject.java index 446eb3ed5..c7521cbf0 100755 --- a/JSONObject.java +++ b/JSONObject.java @@ -1488,7 +1488,6 @@ public String toString(int indentFactor) throws JSONException { * @throws JSONException * If the value is or contains an invalid number. */ - @SuppressWarnings("unchecked") public static String valueToString(Object value) throws JSONException { if (value == null || value.equals(null)) { return "null"; @@ -1513,10 +1512,10 @@ public static String valueToString(Object value) throws JSONException { return value.toString(); } if (value instanceof Map) { - return new JSONObject((Map) value).toString(); + return new JSONObject((Map) value).toString(); } if (value instanceof Collection) { - return new JSONArray((Collection) value).toString(); + return new JSONArray((Collection) value).toString(); } if (value.getClass().isArray()) { return new JSONArray(value).toString(); @@ -1536,7 +1535,6 @@ public static String valueToString(Object value) throws JSONException { * The object to wrap * @return The wrapped value */ - @SuppressWarnings("unchecked") public static Object wrap(Object object) { try { if (object == null) { @@ -1553,13 +1551,13 @@ public static Object wrap(Object object) { } if (object instanceof Collection) { - return new JSONArray((Collection) object); + return new JSONArray((Collection) object); } if (object.getClass().isArray()) { return new JSONArray(object); } if (object instanceof Map) { - return new JSONObject((Map) object); + return new JSONObject((Map) object); } Package objectPackage = object.getClass().getPackage(); String objectPackageName = objectPackage != null ? objectPackage @@ -1588,7 +1586,6 @@ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); } - @SuppressWarnings("unchecked") static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent) throws JSONException, IOException { if (value == null || value.equals(null)) { From 1c11e8a531e3078b51585df92d1019c92aa4f94c Mon Sep 17 00:00:00 2001 From: Christophe SAUVEUR Date: Mon, 4 May 2015 00:32:53 +0200 Subject: [PATCH 3/4] Restored local @SuppressWarnings --- JSONObject.java | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/JSONObject.java b/JSONObject.java index c7521cbf0..0d27702c9 100755 --- a/JSONObject.java +++ b/JSONObject.java @@ -1512,10 +1512,14 @@ public static String valueToString(Object value) throws JSONException { return value.toString(); } if (value instanceof Map) { - return new JSONObject((Map) value).toString(); + @SuppressWarnings("unchecked") + Map map = (Map) value; + return new JSONObject(map).toString(); } if (value instanceof Collection) { - return new JSONArray((Collection) value).toString(); + @SuppressWarnings("unchecked") + Collection coll = (Collection) value; + return new JSONArray(coll).toString(); } if (value.getClass().isArray()) { return new JSONArray(value).toString(); @@ -1551,13 +1555,17 @@ public static Object wrap(Object object) { } if (object instanceof Collection) { - return new JSONArray((Collection) object); + @SuppressWarnings("unchecked") + Collection coll = (Collection) object; + return new JSONArray(coll); } if (object.getClass().isArray()) { return new JSONArray(object); } if (object instanceof Map) { - return new JSONObject((Map) object); + @SuppressWarnings("unchecked") + Map map = (Map) object; + return new JSONObject(map); } Package objectPackage = object.getClass().getPackage(); String objectPackageName = objectPackage != null ? objectPackage @@ -1595,9 +1603,13 @@ static final Writer writeValue(Writer writer, Object value, } else if (value instanceof JSONArray) { ((JSONArray) value).write(writer, indentFactor, indent); } else if (value instanceof Map) { - new JSONObject((Map) value).write(writer, indentFactor, indent); + @SuppressWarnings("unchecked") + Map map = (Map) value; + new JSONObject(map).write(writer, indentFactor, indent); } else if (value instanceof Collection) { - new JSONArray((Collection) value).write(writer, indentFactor, + @SuppressWarnings("unchecked") + Collection coll = (Collection) value; + new JSONArray(coll).write(writer, indentFactor, indent); } else if (value.getClass().isArray()) { new JSONArray(value).write(writer, indentFactor, indent); From 58ce77749e2fd8b1b5b65fdf4a7aef31b7bdb3b8 Mon Sep 17 00:00:00 2001 From: Christophe SAUVEUR Date: Mon, 4 May 2015 09:30:10 +0200 Subject: [PATCH 4/4] Fixed formatting issue --- JSONObject.java | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/JSONObject.java b/JSONObject.java index 0d27702c9..d376ea052 100755 --- a/JSONObject.java +++ b/JSONObject.java @@ -1512,13 +1512,13 @@ public static String valueToString(Object value) throws JSONException { return value.toString(); } if (value instanceof Map) { - @SuppressWarnings("unchecked") - Map map = (Map) value; + @SuppressWarnings("unchecked") + Map map = (Map) value; return new JSONObject(map).toString(); } if (value instanceof Collection) { - @SuppressWarnings("unchecked") - Collection coll = (Collection) value; + @SuppressWarnings("unchecked") + Collection coll = (Collection) value; return new JSONArray(coll).toString(); } if (value.getClass().isArray()) { @@ -1555,16 +1555,16 @@ public static Object wrap(Object object) { } if (object instanceof Collection) { - @SuppressWarnings("unchecked") - Collection coll = (Collection) object; + @SuppressWarnings("unchecked") + Collection coll = (Collection) object; return new JSONArray(coll); } if (object.getClass().isArray()) { return new JSONArray(object); } if (object instanceof Map) { - @SuppressWarnings("unchecked") - Map map = (Map) object; + @SuppressWarnings("unchecked") + Map map = (Map) object; return new JSONObject(map); } Package objectPackage = object.getClass().getPackage(); @@ -1603,12 +1603,12 @@ static final Writer writeValue(Writer writer, Object value, } else if (value instanceof JSONArray) { ((JSONArray) value).write(writer, indentFactor, indent); } else if (value instanceof Map) { - @SuppressWarnings("unchecked") - Map map = (Map) value; + @SuppressWarnings("unchecked") + Map map = (Map) value; new JSONObject(map).write(writer, indentFactor, indent); } else if (value instanceof Collection) { - @SuppressWarnings("unchecked") - Collection coll = (Collection) value; + @SuppressWarnings("unchecked") + Collection coll = (Collection) value; new JSONArray(coll).write(writer, indentFactor, indent); } else if (value.getClass().isArray()) {