Bug 17407 - `Java.IO.BufferedOutputStream(new FileOutputStream(file))` fails to compile due to type incompatibility
Summary: `Java.IO.BufferedOutputStream(new FileOutputStream(file))` fails to compile d...
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.12.0
Hardware: PC Mac OS
: Normal enhancement
Target Milestone: ---
Assignee: dean.ellis
Depends on:
Reported: 2014-01-23 21:09 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2017-06-28 19:19 UTC (History)
2 users (show)

Tags: bb
Is this bug a regression?: ---
Last known good build:

Test case (11.00 KB, application/zip)
2014-01-23 21:09 UTC, Brendan Zagaeski (Xamarin Team, assistant)

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 17407 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Brendan Zagaeski (Xamarin Team, assistant) 2014-01-23 21:09:36 UTC
Created attachment 5907 [details]
Test case

## Steps to reproduce

Attempt to build the solution in the attached test case.

## Result

The compilation fails because FileOutputStream is not a valid input to the `BufferedOutputStream(Stream)` constructor.

> error CS1502: The best overloaded method match for `Java.IO.BufferedOutputStream.BufferedOutputStream(System.IO.Stream)' has some invalid arguments
> error CS1503: Argument `#1' cannot convert `Java.IO.FileOutputStream' expression to type `System.IO.Stream'

## Workaround?

`BufferedOutputStream(System.IO.Stream)` will happily take a System.IO.FileStream as an argument to the constructor, so the following compiles without error:

new BufferedOutputStream(System.IO.File.OpenWrite(file))

## Possible enhancement

- Perhaps `FileOutputStream` could be made convertible to `System.IO.Stream`?

- Or maybe another set of constructors could be added to `BufferedOutputStream` to allow passing in `Java.IO.OutputStream` arguments?

Comment 1 Jonathan Pryor 2014-07-28 17:59:46 UTC
Rephrased: generator should overload constructors and methods which take a *Stream Java type (which is currently bound as System.IO.Stream) and generate _two_ constructors/methods: one taking the current System.IO.Stream type, and one to take the original Java type.
Comment 2 Tom Opgenorth 2017-06-28 19:19:00 UTC
Can duplicate this error using the provided sample.