2

I am developing a CRUD type web application. It is a project management system having projects, milestones, tasks, employees etc. Each employee has his/her own account to login and view the system. The problems come here:

  1. If one user deletes a task while the second has it opened at the same time, the second user will get a null pointer exception if he tries edit and save, because the object doesn't exist.

  2. The same problem in a bit different situation. One user has a task window opened. The second user deletes one employee. The first user tries to assign a task to deleted employee (because it is already in the list in a combobox) and gets null pointer exception.

  3. If someone deletes the object and the other user tries to open it at the same time (will be a null pointer exception when trying to get an item)

I am trying to leave technical details of the project because it is up to that. But if it helps, I'm using Vaadin framework based on Java. The database is MySQL.

I thought two possible solutions but not sure about them:

  1. Catch null pointer exception and print a general warning to the screen ("Some objects are missing...). But it wouldn't be clear for the users that exactly has happened.

  2. Check every commit of the object and if it was deleted catch the exception and give more detailed explanation. But it won't help in the 3rd situation.

I am really looking for any guiding points, advice, or tips you can provide on how to properly deal with these situations. Thank you in advance!

6

The proper way to handle this is to lock the object when the first user starts editing it, and have the application check for locks on an object before deleting it.

For example, you could have a tasks_locks table that looks like this:

task_locks
----------
  task_id
  user_id
  lock_timestamp

When a user goes to edit a task, the application should insert a row into this table, with the Id of the task , the ID of the user, and the current time. This way, when another use tries to delete that task, the application will see a lock record indicating that the task cannot be modified and should inform the user that the task cannot be deleted. When the first users saves their edit, this row can be removed from the task_locks table. Only then can the other user delete the task.

Of course, you'll want to handle situations where a lock never gets released (maybe the client was disconnected before they could complete their edit) so you'll need some procedure to purge locks. It could be manual, it could be automatic (i.e. delete all locks that are more than 60 minutes old), but it's something that should be considered.

With the first solution you propose, the user could spend a lot of time entering data, only to get a NullPointerException. Then they have to re-enter all the data and hope that no one messes around with their dependencies while they're working.

Your second solution just seems to catch the error in a different place so that the user gets a better message, but it won't solve the problem of them having to re-do all of their work when a record they are dependent on is deleted.

  • 1
    A better action when a user tries to delete an object is to flag the object itself as "delete me", and inform all users who have it open. (You ARE informing users that someone else is editing that task right?) – DougM Dec 6 '13 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.