0

My laptop died while programming, the class file in question was saved a few moments before it happened. When i started eclipse again I couldn’t open my workspace because of some error, so I deleted .metadata from my workspace and imported my peoject again.

All my class files are fine, except the one I was working on before my laptop died... which has months of work on it.

I have a back-up project from a few days back, tried importing it but the exact same problem remains. And I can’t restore the file from local history cause apparently there is none.

The file has no code in it, no imports or anything. There is an error on line 1 which is empty, telling me its a syntax error. Nothing I do removes this error. Please help

Dharman
  • 30,962
  • 25
  • 85
  • 135
Buk Lau
  • 33
  • 5
  • 1
    The local history is in the .metadata, which you deleted so it is gone. Deleting the .metadata is always a very bad thing to do despite what you might see in various answers. I don't understand what you are saying happens when you import the old project. – greg-449 Nov 17 '21 at 11:07
  • When I import the old project the class file is stille empty, other than its all the same. – Buk Lau Nov 17 '21 at 11:12
  • Its almost like its corrupted since there is an syntax error on line 1 which is empty. – Buk Lau Nov 17 '21 at 11:13
  • I presume you mean a '.java' when you say a class file, '.class' files are binary compiled code. Can you look at the Java file from the backup outside of Eclipse? Does it look ok? – greg-449 Nov 17 '21 at 11:19
  • 1
    Lesson learned. Always use git and push to a remote origin. – m0skit0 Nov 17 '21 at 11:25
  • The .log file that described the error when I opened my project for the first time had all of my code from the corrupted file, so I just deleted the file from my project then copy-pasted the code. So problem solved! – Buk Lau Nov 17 '21 at 11:26
  • The lesson to learn is take lots of backups, and use a source control system like git or svn. If your code is important and would take a long time to get back you should put a significant amount of effort in to ensuring you have working backups. Remember disks can fail, computers can get stolen, the building could burn down, so off-site backups are also important. – greg-449 Nov 17 '21 at 11:47
  • Indeed, lesson learned. I got 3 different USBs, cloud backups and an air-gapped pc as backup which would be useless without this log file... Expect the unexpected – Buk Lau Nov 17 '21 at 12:00
  • @m0skit0 You missed the point. Deleting the .metadata folder erased the local history. So the files cannot be restored. Deleting the .metadata folder is a hoax spread on Stack Overflow. Never ever delete the .metadata folder. – howlger Nov 17 '21 at 14:47
  • @howlger If the .metadata folder was on a source repository, there wouldn't be any problem. In any case you don't need any .metadata folder if your code is on source control. – m0skit0 Nov 17 '21 at 15:07
  • @m0skit0 Local history, version control and backup are different things, although there are overlaps. The .metadata folder should not be shared. Here, the files were irreversibly deleted by the deletion of the .metadata folder which is a hoax spread on Stack Overflow (never ever delete the .metadata folder). – howlger Nov 17 '21 at 15:29
  • @howlger Again, all of that does not matter if you have source version control. – m0skit0 Nov 17 '21 at 15:42
  • @m0skit0 You oversimplify it. Version control is a good thing, but might also lead to accidental deletion due to making mistakes when merging, force pushing, etc. Version control also only helps if you have at least committed the changes. The mistake that was made here was the deletion of the .metadata folder. Deleting the .metadata folder is a bad idea, similar to deleting the .git folder. Please help to stop the spread of this hoax, as it is causing damage. – howlger Nov 17 '21 at 16:00
  • @howlger [Wrong](https://stackoverflow.com/questions/7147680/accidentally-reverted-to-master-lost-uncommitted-changes). I'm not encouraging the deletion of .metadata. I'm stating SVC will help you avoid losing data and recover it in case you accidentally delete it. Always use SVC, it's more flexible and reliable than any recovery tool from any IDE. – m0skit0 Nov 17 '21 at 16:21
  • @m0skit0 In Git you _can_ rewrite the history which might result in losing data and you can also force push that. Imagine someone loses the local Git config by following the advice spread on Stack Overflow to delete the .git folder. Someone else comments on that with _"Lesson learned. Do regular backups"_. Same spirit. – howlger Nov 17 '21 at 16:46
  • @m0skit0 While it's correct that git CAN be used for backup and that this is much better than nothing, it's not it's purpose and it's much better to use it for what it is intended for - which is version controlling - and use something else for the actual backup. If you really want to use git for backup, then use two layers. Work within one repo, and put that repo into the backup repo. Then make sure the wrapper backup repo is reguarly commited and pushed automatically. But then it's much better to use rsync. – klutt Nov 19 '21 at 07:31
  • @m0skit0 So while it's a good idea to always use git (or something similar) while coding, pushing to a remote is not something you "should always do". If you're setting up a remote git just for this purpose, why not use a real backup system instead? – klutt Nov 19 '21 at 08:25

1 Answers1

1

If this happens to anyone, I found all of my code inside the .log file that appeared when I could not open the project. So I deleted .metadata, deleted my file with code in it, then just copy-pasted it from the .log file.

Then again, deleting .metadata is a bad idea so avoid it if you can.

Buk Lau
  • 33
  • 5
  • Deleting the `.metadata` folder is always a bad idea since it can cause damage. It can always be avoided. If running with `-clean` does not help, create a new workspace and import the projects. – howlger Nov 17 '21 at 14:50