Bug 207095 - [api][breaking] Change ISubSystem#checkIsConnected() API to avoid NPE in FileServiceSubSystem.getRemoteFileObject when subsystem is not connected
Summary: [api][breaking] Change ISubSystem#checkIsConnected() API to avoid NPE in File...
Status: RESOLVED FIXED
Alias: None
Product: Target Management
Classification: Tools
Component: RSE (show other bugs)
Version: 2.0.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M3   Edit
Assignee: David McKnight CLA
QA Contact: Martin Oberhuber CLA
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks: 233435
  Show dependency tree
 
Reported: 2007-10-22 17:54 EDT by Ankit Pasricha CLA
Modified: 2008-05-22 08:26 EDT (History)
2 users (show)

See Also:


Attachments
patch for implicit connect and dealing with NPEs in dstore file service (18.95 KB, patch)
2007-10-24 10:11 EDT, David McKnight CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ankit Pasricha CLA 2007-10-22 17:54:21 EDT
I have a plugin that calls FileServiceSubSystem.getRemoteFileObject on a linux system. When the system is not connected, this code throws an NPE:

java.lang.NullPointerException
	at org.eclipse.rse.services.dstore.AbstractDStoreService.getMinerElement(AbstractDStoreService.java:75)
	at org.eclipse.rse.services.dstore.AbstractDStoreService.getMinerElement(AbstractDStoreService.java:68)
	at org.eclipse.rse.internal.services.dstore.files.DStoreFileService.getElementFor(DStoreFileService.java:1297)
	at org.eclipse.rse.internal.services.dstore.files.DStoreFileService.getFile(DStoreFileService.java:767)
	at org.eclipse.rse.internal.services.dstore.files.DStoreFileService.getUserHome(DStoreFileService.java:889)
	at org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem.getUserHome(FileServiceSubSystem.java:264)
	at org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem.getRemoteFileObject(FileServiceSubSystem.java:187)

I expect RSE to try and connect (i.e. the password dialog should come up) and if I press Cancel then this call should return null (or something appropriate) instead of throwing an NPE.
Comment 1 Martin Oberhuber CLA 2007-10-23 07:43:00 EDT
Throwing an NPE is certainly the wrong thing, but I'd be very careful with an implicit connect during getRemoteFileObject().

The risk with implicit connect is that when a user manually disconnects a connection, some client code still wants a file object reference after disconnect so the system would immediately reconnect.

Currently, API Docs of IRemoteFileSubSystem#getRemoteFileObject() don't tell whether it does an implicit connect or not. The docs just say that it can be a long-running operation, and that it may throw a SystemMessageException.

Because of these API docs, and we don't want to change API if we don't have to, I think we should never return null, but throw a SystemMessageException if anything goes wrong. We might want to introduce a special subclass of SystemMessageException to handle the "not connected" case. API Docs should be extended to explain what happens if the subsystem is not connected.

This would be a great candidate for a Unit Test, such that we can verify all our subsystems (ssh, ftp, dstore) show the same behavior on a disconnected system.

Dave - what do you think?
Comment 2 David McKnight CLA 2007-10-24 10:09:20 EDT
(In reply to comment #1)
> ...
> The risk with implicit connect is that when a user manually disconnects a
> connection, some client code still wants a file object reference after
> disconnect so the system would immediately reconnect.
> 

For the older IBM RSE, we did do the implicit connect whenever a subsystem query API was called and we were not connected.  IBM products were able to make the assumption that such calls could be made without having to worry about the connected state.  The subsystem method we used is still around - checkIsConnected().  As far as the client code referencing a file object after disconnect, we didn't have a problem - only when the user tried to do some kind of query with the referenced object did we implicitly reconnect.


> I think we should never return null, but throw a SystemMessageException if
> anything goes wrong. We might want to introduce a special subclass of
> SystemMessageException to handle the "not connected" case. API Docs should be
> extended to explain what happens if the subsystem is not connected.
> 

If we do decide to put the implicit connect back, then we're unlikely to run into the case of having to return null or throw the system message exception.

Personally, I'm in favour of bringing back implicit connect for getRemoteFileObject() calls (and possibly others) since it's intuitive, convenient and historical for IBM products.


Comment 3 David McKnight CLA 2007-10-24 10:11:28 EDT
Created attachment 81062 [details]
patch for implicit connect and dealing with NPEs in dstore file service

I've attached a patch that deals with NPEs in the dstore file service layer and also does implicit connect in FileServiceSubSystem.getRemoteFileObject() if required.
Comment 4 Martin Oberhuber CLA 2007-10-25 08:42:29 EDT
Ok, if it's always been like that (implicit connect) then we better fix it rather than changing it all.

I'd love to see JUnit tests for the implicit connect, such that we can verify that all FileService implementations show the same behavior.
Comment 5 David McKnight CLA 2007-10-25 12:29:11 EDT
I've committed the code to cvs.  I ended up changing checkIsConnected() to take a progress monitor since, by the way it is used, we should be running the connect in the same job as the caller operation.  

I've also added a test case, FileSubsystemConsistencyTestCase, for comparing behaviours like this using the different service implementations.  Currently FTP is failing, so I'll need to figure that one out.
Comment 6 David McKnight CLA 2007-10-25 13:12:57 EDT
The problem I had with ftp was in the testcase.  I'll close this now.
Comment 7 Martin Oberhuber CLA 2007-10-31 13:07:31 EDT
Marking as breaking API since we changed
   ISubSystem#checkIsConnected()
into
   ISubSystem#checkIsConnected(IProgressMonitor)
Comment 8 Ankit Pasricha CLA 2008-05-16 00:19:08 EDT
I just ran into another variation of this problem. A call to SubSystem.resolveFilterStrings(*) does not prompt for a connection when the subsystem is not connected. I believe the old IBM server used to prompt.
Comment 9 Martin Oberhuber CLA 2008-05-20 17:04:11 EDT
Ankit please file a new bug for your issue.