Skip to content

ClassCastException when trying to get Element from Node #4202

@schabe77

Description

@schabe77

Describe the bug

Hi,
I'm using aws-cdk for java. After upgrading the artifact software.amazon.jsii:jsii-runtime from version 1.85.0 to 1.86.0 a lot of my stacks don't compile anymore. Here an example stack

public class RolesAnywhereStack extends Stack {
    public RolesAnywhereStack(App parent) {
        super(parent, "RolesAnywhereStack");
        final Role bastionRole = Role.Builder.create(this, "RolesAnywhereBastionRole")
                .assumedBy(new ServicePrincipal("rolesanywhere.amazonaws.com"))
                .description("Role that is used when connecting via RolesAnywhere")
                .build();
        CfnRole cfnRole = (CfnRole) bastionRole.getNode().getDefaultChild();
    }
}

when running cdk synthesize RolesAnywhereStack a ClassCastException occurs:

Caused by: java.lang.ClassCastException: class software.constructs.Construct cannot be cast to class software.amazon.awscdk.services.iam.CfnRole (software.constructs.Construct and software.amazon.awscdk.services.iam.CfnRole are in unnamed module of loader java.net.URLClassLoader @7486e0ca)

with jsii-runtime 1.85.0 everything works fine.

Expected Behavior

No ClassCastException

Current Behavior

ClassCastException

Reproduction Steps

try to synthesize this stack

public class RolesAnywhereStack extends Stack {
    public RolesAnywhereStack(App parent) {
        super(parent, "RolesAnywhereStack");
        final Role bastionRole = Role.Builder.create(this, "RolesAnywhereBastionRole")
                .assumedBy(new ServicePrincipal("rolesanywhere.amazonaws.com"))
                .description("Role that is used when connecting via RolesAnywhere")
                .build();
        CfnRole cfnRole = (CfnRole) bastionRole.getNode().getDefaultChild();
    }
}

Possible Solution

No response

Additional Information/Context

No response

SDK version used

software.amazon.jsii:jsii-runtime:1.85.0

Environment details (OS name and version, etc.)

Debian openjdk version "17.0.2" 2022-01-18 OpenJDK Runtime Environment (build 17.0.2+8-86) OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions