Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 359526 - NPE in DomainModelWorkspaceSynchronizerDelegate
Summary: NPE in DomainModelWorkspaceSynchronizerDelegate
Status: CLOSED FIXED
Alias: None
Product: Graphiti
Classification: Modeling
Component: Core (show other bugs)
Version: 0.8.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 0.9.0   Edit
Assignee: Tim Kaiser CLA
QA Contact:
URL:
Whiteboard: Juno M3 theme_bugs Indigo SR2
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-30 04:03 EDT by saurav sarkar CLA
Modified: 2012-06-28 10:47 EDT (History)
2 users (show)

See Also:
michael.wenz: juno+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description saurav sarkar CLA 2011-09-30 04:03:56 EDT
Hi All,

I am unable to refresh my Grpahiti editor inpsite of the underlying resource getting refreshed.I suspect the issue in the NPE i am getting in DomainModelWorkspaceSynchronizerDelegate.

Please note my file system is not local hence the local root is not formed and the time stamp comparison in the DomainModelWorkspaceSynchronizerDelegate fails and eventually it fails to set the resourcechanged flag to true.

For more details and discussions please check.

http://www.eclipse.org/forums/index.php/t/243237/

Let me know if i need to provide any further details or if any help in testing is required.

cheers,
Saurav
Comment 1 Hernan Gonzalez CLA 2011-10-01 15:44:47 EDT
As I pointed out in the linked discussion, the point is not only to avoid a potential NPE. First, I'm not clear whether it's really correct to check all resources for timestamp changes in that method (we're being notified of a change in particular resource, I think we'd check that one only). Further, it's not clear either what you we do in case we can't check timestamps (eg. because it's not actually a file). In my proposed patch a took a middle approach (consider it changed if it's the resource notified), but I doubt this is the right way:

 DomainModelWorkspaceSynchronizerDelegate.handleResourceChanged() 

Proposal 1: (check all, setResourceChanged if NPE with notified resource)

  Resource r = iterator.next();
  IFile file = WorkspaceSynchronizer.getFile(r);
  try {
    if (file != null && (!file.exists() || file.getLocation().toFile().lastModified() != r.getTimeStamp())) {
       deb.setResourceChanged(true);
       return true;
      }
  } catch(Exception e) {
   if(r == resource) {
      deb.setResourceChanged(true);
      return true;
   }
 }


Proposal 2: (check only notified resource, setResourceChanged if NPE )


  IFile file = WorkspaceSynchronizer.getFile(resource);
  try {
    if (file != null && (!file.exists() || file.getLocation().toFile().lastModified() != resource.getTimeStamp())) {
       deb.setResourceChanged(true);
       return true;
      }
  } catch(Exception e) {
      deb.setResourceChanged(true);
      return true;
 }


Proposal 3: (check all resources, setResourceChanged if NPE )

  Resource r = iterator.next();
  IFile file = WorkspaceSynchronizer.getFile(r);
  try {
    if (file != null && (!file.exists() || file.getLocation().toFile().lastModified() != r.getTimeStamp())) {
       deb.setResourceChanged(true);
       return true;
      }
  } catch(Exception e) {
      deb.setResourceChanged(true);
      return true;
  }


I'd vote for 2. (Actually, I'd vote to factor this logic out of here, to some user-provided/hoookable method, but that's other discussion)
Comment 2 Tim Kaiser CLA 2011-10-04 09:10:29 EDT
Hernan, thanks for your hints!
I agree that it is not necessary to check all files in the resource set, since the
change is not reported resource specific.
I did the following changes:
- remove iteration over all resources in resource set
- getUnderlying File instead of getFile (also takes into account archives, seems to be more flexible)
- if the file is null we inform the diagram editor behavior that something changed
- otherwise we stick to general eclipse IFile interface and ask getLocalTimeStamp, if there is no local time stamp
 this method returns a NULL_TIMESTAMP and we notify for changes

Saurav, does it work now for your use case?
Comment 3 Michael Wenz CLA 2011-10-05 03:20:04 EDT
The fix looks good to me and should solve the issues mentioned here. Saurav: please just let us know in case this does not help.
Comment 4 saurav sarkar CLA 2011-10-07 02:18:41 EDT
(In reply to comment #3)
> The fix looks good to me and should solve the issues mentioned here. Saurav:
> please just let us know in case this does not help.

Hi Michael/ Tim,

Thanks for the quick reply.
Fix looks good

Would it mean if the time stamp comparison fails, the resource changed flag is set to true ? and on editor activation the new resource is loaded ?

Can you please provide me the patch or is it submitted ?,I would do testing and let you know.


cheers,
Saurav
Comment 5 Michael Wenz CLA 2011-10-07 03:40:38 EDT
(In reply to comment #4)
> Would it mean if the time stamp comparison fails, the resource changed flag is
> set to true ? and on editor activation the new resource is loaded ?
Yes, that would mean it.

> 
> Can you please provide me the patch or is it submitted ?,I would do testing and
> let you know.
The fix has been checked in to head and will be part of our Juno M3 shipment. For now it can be installed from our nightly build update site at http://download.eclipse.org/graphiti/updates/nightly/

Michael
Comment 6 saurav sarkar CLA 2011-10-07 04:10:18 EDT
(In reply to comment #5)
> (In reply to comment #4)
> > Would it mean if the time stamp comparison fails, the resource changed flag is
> > set to true ? and on editor activation the new resource is loaded ?
> Yes, that would mean it.
> > 
> > Can you please provide me the patch or is it submitted ?,I would do testing and
> > let you know.
> The fix has been checked in to head and will be part of our Juno M3 shipment.
> For now it can be installed from our nightly build update site at
> http://download.eclipse.org/graphiti/updates/nightly/
> Michael

Any chances of getting it submitted in 0.8.0 ,our development is on Indigo. ?

cheers,
Saurav
Comment 7 Michael Wenz CLA 2011-10-07 04:33:26 EDT
(In reply to comment #6)
> Any chances of getting it submitted in 0.8.0 ,our development is on Indigo. ?

Our Juno M3 version (Graphiti 0.9.0 for now) will be compatible with Indigo. So you can test the fix in that version. In parallel we will check if a downport to 0.8.2 (part of Indigo SR2) is possible.

Michael
Comment 8 Michael Wenz CLA 2011-10-19 09:16:04 EDT
(In reply to comment #6)
> Any chances of getting it submitted in 0.8.0 ,our development is on Indigo. ?
> cheers,
> Saurav

I have downported the fix to our 0_8_x codeline; it will be part of our Indigo SR2 shipment
Comment 9 saurav sarkar CLA 2011-11-09 05:47:50 EST
Hi Michael,

Thanks for the info.
The NPE from DomainModelWorkspaceSynchronizer is not coming now and the flag is also set to true.

Then from my editor refresh i call DiagramEditor.setFocus() to reload the model.
But while doing it i get org.eclipse.emf.ecore.xmi.UnresolvedReferenceException: Unresolved reference from my diagram file.

It was thrown during the refreshContent of DiagramEditorInternal

DiagramEditorInput diagramEditorInput = (DiagramEditorInput) getEditorInput();
			Diagram diagram = diagramEditorInput.getDiagram();

Let me know if you can provide me any hints.

cheers,
Saurav
Comment 10 Michael Wenz CLA 2011-11-09 08:30:12 EST
(In reply to comment #9)
> Hi Michael,
> Thanks for the info.
> The NPE from DomainModelWorkspaceSynchronizer is not coming now and the flag is
> also set to true.
> Then from my editor refresh i call DiagramEditor.setFocus() to reload the
> model.
> But while doing it i get
> org.eclipse.emf.ecore.xmi.UnresolvedReferenceException: Unresolved reference
> from my diagram file.
> It was thrown during the refreshContent of DiagramEditorInternal
> DiagramEditorInput diagramEditorInput = (DiagramEditorInput) getEditorInput();
>             Diagram diagram = diagramEditorInput.getDiagram();
> Let me know if you can provide me any hints.
> cheers,
> Saurav

Hi Saurav,
thanks for letting me know that the fix works.
The other thing you mentioned seems to be a different issue, so I would recommend to deal with that in a different topic e.g. in the forum to not mix things here.
Nevertheless, it seems as if your resource(s) are not consistent, so there is a reference to an object that cannot be found.

Michael
Comment 11 saurav sarkar CLA 2011-11-09 09:22:44 EST
Hi Michael,

You are quite right.I would open a different thread in the forum to discuss the issue if required :).

cheers,
Saurav
Comment 12 Michael Wenz CLA 2012-04-11 10:42:44 EDT
Bookkeeping: Set target release
Comment 13 Michael Wenz CLA 2012-06-28 10:47:21 EDT
Part of Graphiti 0.9.0 (Eclipse Juno)