Skip to content

Exception when deleting project #169

Open

Description

@Death111

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

final List<Project> changedProjects = new ArrayList<>(size - removedIndex);

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

Activity

  1. Death111 commented on Nov 9, 2023

    @Death111
    CollaboratorAuthor

    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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions