From 0c69b64e77e04498e09741420f14cae0e49056bf Mon Sep 17 00:00:00 2001 From: Kui LIU Date: Tue, 10 Oct 2017 15:48:03 +0200 Subject: [PATCH] Fix the impossible downcast of toArray(). This code is casting the result of this.items.toArray() on a list to the String type. This will usually fail by throwing a ClassCastException. The toArray() of almost all collections return an Object[]. They can't really do anything else, since the Collection object has no reference to the declared generic type of the collection. The correct and efficient way to get a string array from a list is to use list.toArray(new String[list.size()]);. http://findbugs.sourceforge.net/bugDescriptions.html#BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY --- src/main/java/org/json/simple/ItemList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/json/simple/ItemList.java b/src/main/java/org/json/simple/ItemList.java index 07231e67..56cc6a24 100644 --- a/src/main/java/org/json/simple/ItemList.java +++ b/src/main/java/org/json/simple/ItemList.java @@ -40,7 +40,7 @@ public List getItems(){ } public String[] getArray(){ - return (String[])this.items.toArray(); + return (String[])this.items.toArray(new String[this.items.size()]); } public void split(String s,String sp,List append,boolean isMultiToken){