I looked into it out of curiosity and found no possibility of classCastException could be thrown for the following reason: Firstly, below is the populating logic for HqlSqlWalke's namedParameters` field:
As you can see, either Integer or ArrayList<Integer will be stored as value for an existing named parameter in the namedParameters map. Secondly, here is the reader side code logic in the same class:
The last else branch can only be reached for {{ArrayList<Intege>}}value so it seems safe. Finally, the method in question seems safe to be invoked as well:
We might have avoided such issue if we adopt strict Java generic programming by always storing List<Integer> as the `namedParameters` map value and use the generic types consistently in QueryTranslatorImpl as well. To my knowledge, array is a deprecated thing and its coexistence with Java generics type is the most ugly compromise in JDK’s evolution. |