Skip to content

Framework: Refs with imposed strong types lead to ClassCastException #619

@krestjaninoff

Description

@krestjaninoff

Hello,

I'm trying to create a simple VPC with a single subnet with predefined CIDR using Java:

        VpcNetwork vpc = new VpcNetwork(this, "my-vpc",
                VpcNetworkProps.builder()
                        .withCidr("10.0.0.0/16")
                        .build());
        Token vpcId = vpc.getVpcId();

        new VpcSubnet(this, "my-vpc-a",
                VpcSubnetProps.builder()
                        .withAvailabilityZone(props.getEnv().getRegion() + "a")
                        .withVpcId(vpcId)
                        .withCidrBlock("10.0.1.0/24")
                        .build()

Unfortunately, cdr synth fails with the following error:

Exception in thread "main" java.lang.ClassCastException: software.amazon.awscdk.CloudFormationToken cannot be cast to software.amazon.awscdk.services.ec2.VpcNetworkId
     at software.amazon.awscdk.services.ec2.VpcNetwork.getVpcId(VpcNetwork.java:67)

when vpc.getVpcId() is invoked.

It looks like a bug on Jsii but maybe I'm missing something.


CDK Version: 0.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions