Wednesday, October 1, 2014

Workspace unsaved changes mystery demystified

Are you an Eclipse plug-in developer and you have seen at least once a warning saying something about unsaved changes in the previous session like the one below?


Well, I bet you did, although you probably never paid attention to it since the warning is quite harmless, although can be very annoying. Let me explain why...

The warning is generated during Eclipse startup if your workspace was not properly saved during the previous session. Not properly saved means that something bad happened like process crash, blue screen, power down, etc., and normally you would lost your work. However, Eclipse is able to detect this situation and recover. Not a very fancy recovery, but it does the job and so the warning message is very informative because it's good to know that Eclipse just recovered your work behind the scenes. So far so good.

The annoying part is that it can happen even if you are 100% sure that you closed your Eclipse the right way without any crash and all looked good when you closed it the last time. So, why Eclipse tries to recover something if there is should be nothing to recover?

The answer is that in most cases you didn't do anything wrong and the unsaved change was generated by some badly written plug-in that modified your workspace after you already asked Eclipse to shut down. If you are a curious person like I am, you will probably ask "Fine, but which of the plug-ins is the bad one?" Well, easier said than done. Especially because it happens during shutdown and you will be warned there was some unsaved change during next Eclipse startup. This is a bit too late...

The warning became so annoying that I decided to spend some time to adjust the workspace save behaviour so that we can distinguish unsaved change caused by power down from the one caused by a badly written plug-in and then find out in a semi-automatic way which plug-in is the culprit. Since Eclipse SDK 4.5 build-id I20140930-0800 additional error message will be logged if there is any code that tries to modify your workspace after you already asked Eclipse to stop. Here is an example:


!ENTRY org.eclipse.core.resources 4 10035 2014-09-30 17:27:37.511
!MESSAGE The workspace will exit with unsaved changes in this session. Snapshot requestor: org.eclipse.core.internal.events.NotificationManager$NotifyJob(Updating workspace)
!STACK 0
java.lang.RuntimeException: Scheduling workspace snapshot
 at org.eclipse.core.internal.resources.SaveManager.rememberSnapshotRequestor(SaveManager.java:553)
 at org.eclipse.core.internal.resources.SaveManager.snapshotIfNeeded(SaveManager.java:1476)
 at org.eclipse.core.internal.resources.Workspace.endOperation(Workspace.java:1499)
 at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2321)
 at org.eclipse.core.internal.events.NotificationManager$NotifyJob.run(NotificationManager.java:41)
 at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

If you have auto-build enabled, in most cases the error will mention one of these classes:

org.eclipse.core.internal.events.AutoBuildJob
org.eclipse.core.internal.events.NotificationManager.NotifyJob

This is the code that requested additional workspace save after you manually asked Eclipse to stop but in reality, this is not the problematic part of the code. So, how can you tell which workspace operation triggered an auto-build which in turn requested additional workspace save? Here is where the "semi-" part of the solution plays a role.

Whenever you see an error saying that The workspace will exit with unsaved changes in this session., you already know that some plug-in modified your workspace without your knowledge after you asked Eclipse to stop. In order to find this plug-in you need to enable a few debug options including the new debug option for resource change notifications and then capture the console output to a file.

In the case I investigated, here is what I did:

1. Add -consoleLog to your eclipse.ini file.
2. Run Eclipse using the following command:

eclipsec.exe >> trace.txt 2>&1
3. Go to Window > Preferences > General > Tracing preference page.
4. Enable the Enable tracing option.
5. Expand the Platform Core Resources node and enable the following options:
org.eclipse.core.resources/build/delta=true
org.eclipse.core.resources/build/failure=true
org.eclipse.core.resources/build/interrupt=true
org.eclipse.core.resources/build/invoking=true
org.eclipse.core.resources/build/needbuild=true
org.eclipse.core.resources/build/needbuildstack=true
org.eclipse.core.resources/build/stacktrace=true
org.eclipse.core.resources/debug=true
org.eclipse.core.resources/notifications=true
org.eclipse.core.resources/save=true
Not all of them are strictly necessary, but since you don't want to do this more than once, it's better to gather all the data at first attempt.
6. Start using your Eclipse normally and observe the Error Log view. If you see "The workspace will exit with unsaved changes in this session." error followed by "The workspace exited with unsaved changes in the previous session;..." warning, it is time to look at the trace.txt file.

The relevant part of the trace file is between the line that says:

Tue Sep 30 17:27:34 CEST 2014 - [ModalContext] org.eclipse.core.internal.jobs.ThreadJob(Implicit Job): Full save on workspace:  starting...
and the first line that contains
java.lang.RuntimeException: Scheduling workspace snapshot

Any resource change event that happened between this two lines could be the culprit of unsaved changes so now you need to read the trace file and see which event is suspicious. In my example, it was quite easy because the following event was generated after every full save on workspace:

Type: POST_CHANGE
Build kind: 0
Resource: null
Delta:
/[*]: {}
/External Plug-in Libraries[*]: {}
/External Plug-in Libraries/.searchable[*]: {CONTENT}

What it means is that whenever I ask Eclipse to stop, some plug-in modifies the content of /External Plug-in Libraries/.searchable file as part of the save operation. This results in subsequent resource change events being populated and triggering auto-build and in the end workspace snapshot which will give the unexpected change warning during next startup. Having all this data, the only thing that is left is to find out which plug-in is responsible for /External Plug-in Libraries/.searchable and then fix it.

If you want to see an example how the whole investigation was done in practice, take a look at bug 444988 where one of the problematic plug-ins was identified and will be fixed in the near future hopefully.

Happy hunting! :)

Friday, June 28, 2013

Summary after DemoCamp in Poznan

Eclipse DemoCamp in Poznan is over. It went great and a lot of people showed up. We had 55 people registered from which 44 showed up during the event. Fortunately, the local was big enough to hold everyone. Presentations were very interesting, although after the survey we sent to participants it turned out that those with an actual live demo were more attractive.

Here are some photos of our DemoCamp:

If you want to join us and present something in November, let me know.

See you in November!
Szymon

Wednesday, June 5, 2013

Eclipse DemoCamp in Poznan is coming

The next version of one of the most popular IDEs is almost done. Get ready to be the first to see what's new in it! Join our Eclipse DemoCamp in Poznan and find out!

The event will be hosted at The Brothers Pub on Wednesday, June 12 at 6:30 PM. You can find more information about the event on our wiki page.

If you want to join us, please register, so that we can make sure you can get beer and pizza when you come. And hurry up, because there are not many seats left!

See you there!
Szymon

Tuesday, March 20, 2012

'Ignore optional compile problems' is now available with 3.8/4.2 M6


  • Have you ever been overwhelmed by thousands of potentially unimportant warnings in your Java project?
  • Have you ever tried to avoid excessive error reporting from a source folder containing auto-generated code?
  • Have you ever looked for a specific problem and could not find it because it drowned somewhere in the Problems view?


If answer to any of the above questions is 'Yes', then I have good news for you! Finally, after several busy weeks, we have an option to ignore all configurable compile problems just a few clicks away!

It's really simple!


You can turn on the new Ignore optional compile problems option for each source folder available in your Java project. To do that, go to Project properties > Java Build Path > Source and toggle the value of 'Ignore optional compile problems' to Yes. With this option set to 'Yes', JDT compiler will suppress errors and warnings configured in the Preferences > Java > Compiler > Errors/Warnings page.



Java Build path page with 'Ignore optional compile problems' highlighted



We wouldn't have the new option without great help from Satyam and Markus who spent a lof of time reviewing patches for bug 220928. Thanks guys!


For other noteworthy things available in 3.8/4.2 M6 see the entire New and Noteworthy.

Tuesday, November 29, 2011

Time to say goodbye!

I think I should start this writing from stating that this is a guest post, as I am no longer a member of IBM Eclipse Support crew.

It has been almost 5 entire years since my office was formed as a kind of joint venture between Poznan University of Technology and IBM. My main responsibility was to help customers with their Eclipse related problems. As you know, many IBM Rational products are Eclipse based, even those server-side, so I never had enough time to blog or actively participate in Eclipse development - I barely managed to open a number of bugs that could change how corporations perceived Eclipse and Eclipse-based solutions.

I'd say that my experience gathered on the border of open-source and enterprise worlds is a rather unique one. And I would like to share it with you at EclipseCon.

I guess that my 5 years of work for IBM may be summarized with the following xkcd strip - I just started realizing that careers are hard ;-).
Every age: "I'm glad I'm not the clueless person I was five years ago, but now I don't want to get any older."
If you wonder what I will do next, please stay tuned! I will announce that on my newly created blog once it gets added to the planet Eclipse (I have already opened a bug for that).

I would like to publicly say "Thank you" to Daniel Megert for his incredibly reliable work, not only in JDT - and nominate him to Eclipse Community Awards in recognition.

Thank you for reading this post :). I hope that I will have now much more time for writing.

Krzysztof (Chris) Daniel

Monday, May 30, 2011

A very interesting bug report

One image is worth more than a thousand of words.
Just check this real bug report: