I have a code as below where I am trying to add an ArrayList(componentList) to another ArrayList(SpareParts). It works fine a long as spareParts list is not empty. When the spareParts List is empty it throws java.lang.UnsupportedOperationException: null
List<ProductReferenceData> spareParts = new ArrayList<ProductReferenceData>();
/**
 Method which fills spareParts List and does not return null. Checked in Debugger as well.
*/
if(componentLabels!=null && !CollectionUtils.isEmpty(componentLabels))
 {
    spareParts.addAll(componentLabels);
 }
I can put an if else loop to check if spareParts list is empty to patch this issue but is there an elegant solution to this? Maybe in Java 8
---edit--- Adding stacktrace
INFO   | jvm 1    | main    | 2020/08/07 20:10:39.309 | java.lang.UnsupportedOperationException: null
INFO   | jvm 1    | main    | 2020/08/07 20:10:39.316 |     at java.util.AbstractList.add(AbstractList.java:148) ~[?:1.8.0_172]
INFO   | jvm 1    | main    | 2020/08/07 20:10:39.316 |     at java.util.AbstractList.add(AbstractList.java:108) ~[?:1.8.0_172]
INFO   | jvm 1    | main    | 2020/08/07 20:10:39.316 |     at java.util.AbstractCollection.addAll(AbstractCollection.java:344) ~[?:1.8.0_172]
INFO   | jvm 1    | main    | 2020/08/07 20:10:39.316 |     at com.ge.hc.storefront.controllers.pages.ProductPageController.productDetail(ProductPageController.java:418) ~[classes/:?]
