Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 258173 - [artifact] AbstractArtifactRepository#getOutputStream returns null
Summary: [artifact] AbstractArtifactRepository#getOutputStream returns null
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: p2 (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M5   Edit
Assignee: Andrew Cattle CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-09 15:26 EST by Andrew Cattle CLA
Modified: 2008-12-19 09:49 EST (History)
3 users (show)

See Also:


Attachments
Changes "return null;" to "throw new UnsupportedOperationException" (3.24 KB, patch)
2008-12-17 09:56 EST, Andrew Cattle CLA
no flags Details | Diff
Changes getOutputStream to abstracty method. Implements where appropriate. (6.00 KB, patch)
2008-12-18 14:35 EST, Andrew Cattle CLA
dj.houghton: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Cattle CLA 2008-12-09 15:26:20 EST
Related to Bug 258166.

When testing what would happen if I listed a composite repository as a destination for the mirror application I noticed that a composite artifact repository returns null when getOutputStream is called. This null OutputStream is then used by the mirror application and eventually resulting in a call to an Object.wait() call.

I was thinking that given the API is defined as follows, returning null may be breaking the contract. Perhaps an I/O Exception would be better.

The IArtifactRepository interface defines getOutputStream as:
Open an output stream to which a client can write the data for the given 
artifact descriptor.

And further states:
@return the stream to which the artifact content can be written.
@throws ProvisionException if the output stream could not be created.  Reasons include:
  An I/O exception occurred
  An artifact already exists at that location
Comment 1 John Arthorne CLA 2008-12-09 21:01:32 EST
This method should either be abstract, or throw an exception if isModifiable returns true.
Comment 2 Andrew Cattle CLA 2008-12-11 10:47:07 EST
(In reply to comment #1)
> This method should either be abstract, or throw an exception if isModifiable
> returns true.
> 

What would an appropriate exception be? The contract only defines ProvisionException as being throwable yet ProvisionException is defined as a recoverable exception.

If we change the method to allow us to throw another type of exception we need to modify the catch blocks of every single call to getOutputStream.
Comment 3 DJ Houghton CLA 2008-12-17 08:40:38 EST
I would suggest an unsupported method exception with a message saying that the subclasses must implement it.

Comment 4 Andrew Cattle CLA 2008-12-17 09:56:34 EST
Created attachment 120696 [details]
Changes "return null;" to "throw new UnsupportedOperationException"

I was thinking that since this method will only ever throw an exception, wouldn't it just make more sense to change it to an abstract method? It's provisional so no one but us is supposed to subclass it, so it shouldn't break too much.
Comment 5 Andrew Cattle CLA 2008-12-18 14:35:34 EST
Created attachment 120879 [details]
Changes getOutputStream to abstracty method. Implements where appropriate.

I much prefer this solution to my previous one. The operation isn't Unsupported, it's unimplemented. The error message will mean nothing to the user. Abstract methods and classes exist for this very purpose.

AbstractArtifactRepository is provisional so this should have any affect on any users outside of the 2 internal classes I already modified in this patch.
Comment 6 DJ Houghton CLA 2008-12-19 09:48:53 EST
Released second patch to HEAD which makes the method abstract on the abstract class.

Closing.