Skip to content
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

Java/DotNet: abstract members are not marked as such on their .NET and Java representations. #1011

Closed
rix0rrr opened this issue Nov 19, 2019 · 4 comments · Fixed by #1128
Closed
Assignees
Labels
bug This issue is a bug. in-progress Issue is being actively worked on. language/dotnet Related to .NET bindings (C#, F#, ...) language/java Related to Java bindings p1

Comments

@rix0rrr
Copy link
Contributor

rix0rrr commented Nov 19, 2019

🐛 Bug Report

In this code:

https://github.com/rix0rrr/jsii-test-drive/blob/master/java/extends-abstract-class/src/main/java/com/myorg/MyCode.java

The subclass of Code is not complete. It is missing an implementation of public abstract readonly isInline: boolean.

This class should have been needed to be marked abstract, but it it isn't.

Impact to CDK

  • Abstract members have an implementation in the generated .NET and Java code, allowing classes extending those to omit implementation of some (or all) of the abstract members. While the resulting code compiles, it may fail at run-time due to the missing implementations.
  • Workaround: when extending abstract classes, consult the TypeScript API reference to identify all abstract members of the extended type, and make sure to implement all of those. The members will be made abstract in a subsequent release of the CDK for Java and .NET, which will break invalid implementations.
@rix0rrr rix0rrr added bug This issue is a bug. language/java Related to Java bindings labels Nov 19, 2019
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Nov 19, 2019

This feels wrong-- the abstract-ness of a member should be mirrored into the JSII bindings.

@nija-at nija-at changed the title java: can incompletely implement abstract class java and c#: can incompletely implement abstract class Nov 19, 2019
@nija-at
Copy link
Contributor

nija-at commented Nov 19, 2019

@nija-at nija-at added the language/dotnet Related to .NET bindings (C#, F#, ...) label Nov 19, 2019
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Nov 19, 2019

Accessing the "abstract" member results in a predictable JSII exception:

Unhandled exception. Amazon.JSII.Runtime.JsiiException: Got 'undefined' for non-optional instance of {"abstract":true,"docs":{"stability":"stable","summary":"The name of the function."},"immutable":true,"locationInModule":{"filename":"lib/function-base.ts","line":148},"name":"functionName","overrides":"@aws-cdk/aws-lambda.IFunction","type":{"primitive":"string"}}
   at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
   at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
   at Amazon.JSII.Runtime.Services.Client.Send[TRequest,TResponse](TRequest requestObject)
   at Amazon.JSII.Runtime.Services.Client.Get(GetRequest request)
   at Amazon.JSII.Runtime.Services.Client.Get(ObjectReference objectReference, String property)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.<>c__DisplayClass9_0`1.<GetInstanceProperty>b__0(IClient client)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.GetPropertyCore[T](JsiiPropertyAttribute propertyAttribute, Func`2 getFunc)
   at Amazon.JSII.Runtime.Deputy.DeputyBase.GetInstanceProperty[T](String propertyName)
   at Amazon.CDK.AWS.Lambda.FunctionBase.get_FunctionName()
   at Serverless.Program.Main(String[] args) in /Users/nija/workplace/cdk/jsii-test-drive/dotnet/serverless/src/Serverless/Program.cs:line 36

@RomainMuller RomainMuller changed the title java and c#: can incompletely implement abstract class Java/DotNet: abstract members are not marked as such on their .NET and Java representations. Nov 22, 2019
@RomainMuller
Copy link
Contributor

This is actually a duplicate of #240

RomainMuller added a commit that referenced this issue Dec 16, 2019
The generated code for abstract properties in Java and C# included fully
concrete implementations, instead of an abstract declaration. This made
it possible to subclass those types without actually implementing those
members, resulting in invalid code.

This changes the code generation to actually emit the `abstract` keyword
and not generate a full concrete implementation.

Fixes #240
Fixes #1011
@SomayaB SomayaB added the in-progress Issue is being actively worked on. label Dec 17, 2019
@mergify mergify bot closed this as completed in #1128 Dec 19, 2019
mergify bot pushed a commit that referenced this issue Dec 19, 2019
…1128)

* fix(java,dotnet): abstract properties have concrete implementations

The generated code for abstract properties in Java and C# included fully
concrete implementations, instead of an abstract declaration. This made
it possible to subclass those types without actually implementing those
members, resulting in invalid code.

This changes the code generation to actually emit the `abstract` keyword
and not generate a full concrete implementation.

Fixes #240
Fixes #1011

* add some test coverage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. in-progress Issue is being actively worked on. language/dotnet Related to .NET bindings (C#, F#, ...) language/java Related to Java bindings p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants