doubleSlashde / KeepTime

Application to track your time spent on different projects each day.
GNU General Public License v3.0
8 stars 3 forks source link

Exception when deleting project #169

Open Death111 opened 11 months ago

Death111 commented 11 months ago

Following exception happened when deleting an project:

java.lang.IllegalArgumentException: Illegal Capacity: -1
    at java.base/java.util.ArrayList.<init>(ArrayList.java:158)
    at de.doubleslash.keeptime.controller.Controller.adaptProjectIndexesAfterRemoving(Controller.java:304)
    at de.doubleslash.keeptime.controller.Controller.deleteProject(Controller.java:194)
    at de.doubleslash.keeptime.REST_API.controller.ProjectController.deleteProject(ProjectController.java:111)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)

image https://github.com/doubleSlashde/KeepTime/blob/019bffd40628a53886a4ea2195f1ca71af7b9e52/src/main/java/de/doubleslash/keeptime/controller/Controller.java#L303

Logic seems wrong: List is initialized with a capacity based on the sorting Index - which does not make sense?

Death111 commented 11 months ago

Most likely this cannot happen with a valid database state. If I have e.g. 13 projects, the highest sort index should be 12. So when the logic "size - removedIndex" is executed (13-12) will instantiate a list with initial capacity 1. (It did occure in an invalid state with some REST API experiments which created "invalid" projects)