-
Notifications
You must be signed in to change notification settings - Fork 58
[generator] Fix NRE by cloning method when copying from base type to derived type. #1080
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,57 @@ internal string CalculateEventName (Func<string, bool> checkNameDuplicate) | |
|
||
public bool CanHaveStringOverload => IsReturnCharSequence || Parameters.HasCharSequence; | ||
|
||
public Method Clone (GenBase declaringType) | ||
{ | ||
var clone = new Method (declaringType); | ||
|
||
// MethodBase | ||
clone.Annotation = Annotation; | ||
clone.ApiAvailableSince = ApiAvailableSince; | ||
clone.AssemblyName = AssemblyName; | ||
clone.Deprecated = Deprecated; | ||
clone.DeprecatedSince = DeprecatedSince; | ||
clone.IsAcw = IsAcw; | ||
clone.Name = Name; | ||
clone.Visibility = Visibility; | ||
clone.LineNumber = LineNumber; | ||
clone.LinePosition = LinePosition; | ||
clone.SourceFile = SourceFile; | ||
clone.JavadocInfo = JavadocInfo; | ||
|
||
if (GenericArguments != null) | ||
foreach (var ga in GenericArguments) | ||
clone.GenericArguments.Add (ga.Clone ()); | ||
|
||
foreach (var p in Parameters) | ||
clone.Parameters.Add (p.Clone ()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While writing the draft commit message, my thoughts turn to Rephrased, I would expect that the new Parameter (
name: "value",
type: "java.lang.Object",
managedType: "Java.Lang.Object"
isEnumified: false
); but I don't see this happening. Should this be happening? Or is this instead handled by new lines 128-130 (above), wherein we added |
||
|
||
// Method | ||
clone.ArgsType = ArgsType; | ||
clone.CustomAttributes = CustomAttributes; | ||
clone.EventName = EventName; | ||
clone.GenerateAsyncWrapper = GenerateAsyncWrapper; | ||
clone.GenerateDispatchingSetter = GenerateDispatchingSetter; | ||
clone.IsAbstract = IsAbstract; | ||
clone.IsFinal = IsFinal; | ||
clone.IsInterfaceDefaultMethod = IsInterfaceDefaultMethod; | ||
clone.OverriddenInterfaceMethod = OverriddenInterfaceMethod; | ||
clone.IsReturnEnumified = IsReturnEnumified; | ||
clone.IsStatic = IsStatic; | ||
clone.IsVirtual = IsVirtual; | ||
clone.JavaName = JavaName; | ||
clone.ManagedOverride = ManagedOverride; | ||
clone.ManagedReturn = ManagedReturn; | ||
clone.PropertyNameOverride = PropertyNameOverride; | ||
clone.Return = Return; | ||
clone.ReturnNotNull = ReturnNotNull; | ||
clone.RetVal = RetVal.Clone (clone); | ||
clone.SourceApiLevel = SourceApiLevel; | ||
clone.ExplicitInterface = ExplicitInterface; | ||
|
||
return clone; | ||
} | ||
|
||
public string ConnectorName => $"Get{Name}{IDSignature}Handler"; | ||
|
||
public string EscapedCallbackName => IdentifierValidator.CreateValidIdentifier ($"cb_{JavaName}{IDSignature}", true); | ||
|
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 is this asserting that the method got removed?
OK, this test is asserting that we no longer NRE, that the BG8800 warning is still emitted (implicitly), that
public_class
has no methods, andbase_class.Methods
is still sane.But… shouldn't the "final" fix be a situation in which:
public_class.Methods.Count
is also 1, andpublic_class.Methods[0].IsValid
is true, andpublic_class.Methods[0].Parameters[0].JniType
isjava/lang/Object
?Upon review, it feels like this PR fixes the NRE, but doesn't resolve the underlying scenario allowing publicly accessible members from package-private types to be bound in the derived type.
Is that possible?
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.
Correct, this PR only fixes the NRE. It does not try to fix the underlying issue of correctly supporting generics when copying methods from a
package-private
class. I do not believe that is a topic we want to tackle any time soon.