-
Notifications
You must be signed in to change notification settings - Fork 57
[api-xml-adjuster] method overrides cannot expose non-public types. #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[api-xml-adjuster] method overrides cannot expose non-public types. #94
Conversation
…ster. There were non-breaking API definition files changes caused by dotnet/java-interop#94 This update reflects the changes.
Parent = parent; | ||
} | ||
|
||
public JavaMethodBase Parent { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need a property setter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be private.
f2b8f32
to
a4d5583
Compare
@@ -309,7 +315,7 @@ public JavaTypeParameter (JavaTypeParameters parent) | |||
|
|||
public override string ToString () | |||
{ | |||
return Name + (GenericConstraints == null ? null : GenericConstraints.ToString ()); | |||
return Name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the removal of the constraints from JavaTypeParameter
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically we have right to choose what to output in this ToString() overrides.
There are places that should output generic constraints and that should NOT. When writing generic type parameter definitions they should be there. When writing USE of generic type parameters they should NOT. And this generic constraints part were always written.
An exceptional case that it SHOULD be written for USE of generics is that the name is "?" which is handled specially.
Are the changes in this xamarin-android PR from before or after this PR? |
@@ -18,19 +18,14 @@ public void SetupFixture () | |||
[Test] | |||
public void TypeReferenceEquals () | |||
{ | |||
var intRef = new JavaTypeReference ("int"); | |||
Assert.AreEqual (intRef, new JavaTypeReference ("int"), "primitive types"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these tests invalidated? (Presumably they're invalidated, otherwise why would they be removed?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the revised API (JavaTypeReference.ctor() being non-public), those removed lines don't compile, so they were deleted.
The changes for that xamarin-android PR is after this change. |
Which means it's responsible for this change, which I don't understand or like:
Why would we want to lose |
Goooood catch, kind of ;-) I thought (I guess you did too) that it is only missing "? extends U" and thought it's harmless, but it is actually ", ? extends U" (note that the first comma), so it's just dropping subsequent generic arguments than the first one. I'm rolling a fix, which might be pushed soon or might need more fixes. |
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=44531 When a Java method is overriden, its parameter type or return type can be variant, which possibly result in exposure of non-public types (returning private class object which is derived from public type is totally valid). It is because we blindly emit the parsed type from class-parse output as the API XML adjuster output. It needs to be examined and adjusted to be public (or protected) type. jar2xml didn't have this problem because Java reflection API is clever enough to cover that issue. The fixes are... not cosmetic. Basically now we use TypeReference.ToString() which used to not be precise and ready for API XML output. So there are couple of fixes for that. (We also want to track from which method base a parameter or return type is bound, so we pass that to the .ctor now). We hide extraneous public TypeParameter.ctor() now to reduce chances for bugs. Tests need to be modified to reflect the changes. Lastly, Mono.Android API XML will be updated to reflect this change. There will be some removal of method overrides from api-*.xml.in but there was no regression reported from api-diff.
a4d5583
to
5e91472
Compare
…ster. There were non-breaking API definition files changes caused by dotnet/java-interop#94 This update reflects the changes.
The PRs are updated to reflect the fixes. |
Assert.AreEqual ("V", ga1.GenericArguments [1].FullNameNonGeneric, "genarg#0.2 name mismatch"); | ||
var ga2 = tn.GenericArguments [1]; | ||
Assert.AreEqual ("?", ga2.FullNameNonGeneric, "genarg#1 name mismatch"); | ||
Assert.AreEqual (" extends ", ga2.BoundsType, "genarg#1 incorrect bounds type"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit "odd", in that it means that ga2.BoundsType
contains leading and trailing spaces, e.g. this is " extends "
, not "extends"
.
Should the BoundsType
property not contain spaces, while the spaces are included in e.g. ga2.ToString()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course I thought about that, but I didn't find very reason to perform extra string stripping and cause more memory consumption.
…adjuster (#260) There were non-breaking API definition files changes caused by dotnet/java-interop#94 This update reflects the changes. Additionally, the pre-API-24 API descriptions were generated by `jar2xml`, not `class-parse`, which generated extraneous generic constraints. Update all API descriptions to be generated by `class-parse` and `api-xml-adjuster`.
Changes: dotnet/android-tools@3974fc3...f2af06f * dotnet/android-tools@f2af06f: [Xamarin.Android.Tools.AndroidSdk] Fix a few nullability warnings (#97) * dotnet/android-tools@5718cd2: Fix sort ordering for ndk-bundle, add macOS support (#91) * dotnet/android-tools@8e63795: [Xamarin.Android.Tools.AndroidSdk] Add API-29, API-30 to KnownVersions (#89) * dotnet/android-tools@a6a23bb: [Xamarin.Android.Tools.AndroidSdk] Default SDK component versions (#93) * dotnet/android-tools@32a1e2c: [build] fail macOS build if tests fail (#94) * dotnet/android-tools@79a0141: Return a default for unknown API levels (#90)
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=44531
When a Java method is overriden, its parameter type or return type can be
variant, which possibly result in exposure of non-public types (returning
private class object which is derived from public type is totally valid).
It is because we blindly emit the parsed type from class-parse output
as the API XML adjuster output. It needs to be examined and adjusted to
be public (or protected) type.
jar2xml didn't have this problem because Java reflection API is clever
enough to cover that issue.
The fixes are... not cosmetic.
Basically now we use TypeReference.ToString() which used to not be
precise and ready for API XML output. So there are couple of fixes
for that. (We also want to track from which method base a parameter
or return type is bound, so we pass that to the .ctor now).
We hide extraneous public TypeParameter.ctor() now to reduce chances
for bugs. Tests need to be modified to reflect the changes.
Lastly, Mono.Android API XML will be updated to reflect this change.
There will be some removal of method overrides from api-*.xml.in but
there was no regression reported from api-diff.