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

"Cannot construct instance of <struct>" in callbacks #2951

Closed
1 of 5 tasks
rix0rrr opened this issue Aug 13, 2021 · 1 comment · Fixed by #2952
Closed
1 of 5 tasks

"Cannot construct instance of <struct>" in callbacks #2951

rix0rrr opened this issue Aug 13, 2021 · 1 comment · Fixed by #2952
Assignees
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@rix0rrr
Copy link
Contributor

rix0rrr commented Aug 13, 2021

🐛 Bug Report

Affected Languages

  • TypeScript or Javascript
  • Python
  • Java
  • .NET (C#, F#, ...)
  • Go

General Information

  • JSII Version: whatever CDK 1.118.0 gets built with 😅
  • Platform: Any, tried on Mac

What is the problem?

(Originally reported as aws/aws-cdk#15791)

CDK Pipelines allows users to write their own classes, implementing an interface, that slot into the CDK Pipelines framework. The slightly odd thing is that it requires them to extend one class and implement an unrelated interface:

public class LambdaStep extends Step implements ICodePipelineActionFactory {

When the step.produceAction method finally gets invoked, the Java Runtime doesn't know how to deserialize the ProduceActionOptions struct:

Error: Cannot construct instance of `software.amazon.awscdk.pipelines.ProduceActionOptions` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information

Upon object creation, it seems the runtime is not aware of the interface:

{
  "fqn": "@aws-cdk/pipelines.Step",
  "args": [
    "MyStep"
  ],
  "overrides": [
    {
      "method": "produceAction",
      "cookie": "public software.amazon.awscdk.pipelines.CodePipelineActionFactoryResult com.myorg.LambdaStep.produceAction(software.amazon.awscdk.services.codepipeline.IStage,software.amazon.awscdk.pipelines.ProduceActionOptions)"
    }
  ],
  "interfaces": [],   // <--------- VRONK!
  "api": "create"
}

Repro: https://github.com/rix0rrr/jsii-repro

@rix0rrr rix0rrr added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 13, 2021
@RomainMuller RomainMuller self-assigned this Aug 13, 2021
RomainMuller added a commit that referenced this issue Aug 13, 2021
When extending a "jsii well-known type", additional jsii interfaces
implemented were not registered with the kernel, because of a flaw in
how interface discovery works. The `@Jsii` annotation is `@Inherited`,
meaning that a sub-class of an annotated type is annotated (this is
desirable)... However, this means the fact the annotation is present on
a type does not imply it _is_ a "jsii well-known type"... Instead, we
must check whether the annotation is _declared_ by the current type (if
not, then the annotation is inherited from a parent class).

Fixes #2951
@mergify mergify bot closed this as completed in #2952 Aug 13, 2021
mergify bot pushed a commit that referenced this issue Aug 13, 2021
When extending a "jsii well-known type", additional jsii interfaces
implemented were not registered with the kernel, because of a flaw in
how interface discovery works. The `@Jsii` annotation is `@Inherited`,
meaning that a sub-class of an annotated type is annotated (this is
desirable)... However, this means the fact the annotation is present on
a type does not imply it _is_ a "jsii well-known type"... Instead, we
must check whether the annotation is _declared_ by the current type (if
not, then the annotation is inherited from a parent class).

Fixes #2951



---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants