Issue
I want to add a regular user to the list. I use Postman for this, the request body comes, but when adding, such an error occurs.
@PostMapping
public Developer create(@RequestBody Developer developer) {
System.out.println(developer);
this.DEVELOPERS.add(developer);
return developer;
}
2022-09-11 23:19:53.444 ERROR 30036 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.UnsupportedOperationException] with root cause
java.lang.UnsupportedOperationException: null
at java.base/java.util.ImmutableCollections.uoe(ImmutableCollections.java:142) ~[na:na]
at java.base/java.util.ImmutableCollections$AbstractImmutableCollection.add(ImmutableCollections.java:147) ~[na:na] ...
Solution
Fix for this problem is to Use linkedList
Create a LinkedList, which supports faster remove.
List list = new LinkedList(Arrays.asList(split));
Answered By - Faisal Behram
Answer Checked By - Mary Flores (JavaFixing Volunteer)