-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Framework: Refs with imposed strong types lead to ClassCastException #619
Comments
You're not missing anything. Unfortunately, this cannot work as written right now. |
Here's the issue. This is our inheritance hierarchy:
At some point, we're making the following assignment: this.vpcId = vpc.ref; Apparently, TypeScript allows this because of the structural type checking it employs. Java will do nominal type checking however, and will throw the EDIT: Actually, the terminology is not quite correct. What's called |
An easy fix for this is to change into: this.vpcId = new VpcId(vpc.ref); However, I think we might want to annotate the CloudFormation spec instead and resolve it there. |
Annotate all CloudFormation resource types with the type of their 'Ref' (whether it returns a `Name`, `Id` or `Arn`). We generate specific classes for those types, just like we do for `{Fn::GetAtt}` attributes. This makes it easier to write construct libraries: it removes the need for every construct library to explicitly declare a custom type for the ref implicit type, and reduces chances of a `ClassCastException` in Java if they do it wrong. Generated resource classes no longer implicitly inherit from `Referenceable`, because not all resources even have the `{Ref}` operator defined. Fixes #619.
Hello,
I'm trying to create a simple VPC with a single subnet with predefined CIDR using Java:
Unfortunately,
cdr synth
fails with the following error:when
vpc.getVpcId()
is invoked.It looks like a bug on Jsii but maybe I'm missing something.
CDK Version: 0.8
The text was updated successfully, but these errors were encountered: